Skip to content
Snippets Groups Projects
Commit 73e984ec authored by Yamane's avatar Yamane
Browse files

group week10

parent 65cb00f6
No related branches found
No related tags found
No related merge requests found
Pipeline #294932 passed
# 10. Output devices
This week I worked on defining my final project idea and started to getting used to the documentation process.
## Instruction
## Research
- individual assignment:
add an output device to a microcontroller board you've designed,
and program it to do something
- group assignment:
measure the power consumption of an output device
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
## What I did in this week
> "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
- practice to set up the output device by using arduino →in this page
- try to set it up by using my own breakout board →in this page
- measure the powerconsumption of an output device →in this page
- add an output device to a microcontroller board you've designed →[individual page](https://fabacademy.org/2022/labs/kannai/students/yukiya-yamane/assignments/week11/)
- program it to flash LED →[individual page](https://fabacademy.org/2022/labs/kannai/students/yukiya-yamane/assignments/week11/)
## Useful links
## practice to set up the output device by using arduino
- [Jekyll](http://jekyll.org)
- [Google](http://google.com)
- [Markdown](https://en.wikipedia.org/wiki/Markdown)
I choose Neo Pixel LEDs as an output device. First of all, I try to LED flashing by using arduino.
## Code Example
I refered to this [arduino guide page](https://create.arduino.cc/projecthub/electropeak/neopixel-how-to-control-ws2812-rgb-led-w-arduino-46c08f)
Use the three backticks to separate code.
### Neo Pixel circuit
![arduino.png](../images/week10/arduino.png)
learn about NeoPixel LEDs and how to control them with Arduino.
- Before connecting NeoPixels to any large power source (DC “wall wart” or even a large battery), add a **capacitor** (500–1000 µF at 6.3V or higher) across the + and – terminals as shown above. The capacitor buffers sudden changes in the current drawn by the strip.
- Place a **300 to 500 Ohm resistor** between the Arduino data output pin and the input to the first NeoPixel. The resistor should be at the end of the wire closest to the NeoPixel(s), not the microcontroller. *Some products already incorporate this resistor…if you’re not sure, add one…there’s no harm in doubling up!*
Read **[Adafruit NeoPixel Userguide](https://learn.adafruit.com/adafruit-neopixel-uberguide/best-practices)**
### Design Circuit
- wiring arduino uno to bread board which connect to NeoPixel
![arduino_circuit.jpeg](../images/week10/arduino_circuit.jpeg)
- Program it
**Test 1 :Blink mode**
```jsx
/*
NeoPixel LEDs
modified on 7 May 2019
by Saeed Hosseini @ Electropeak
https://electropeak.com/learn/
*/
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
#define PIN 6
#define NUMPIXELS 8
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void NeoBlink(int num, int wait)
{
for (int i = 0; i < num; i++)
{
pixels.setPixelColor(i, 35, 35, 35);
}
pixels.show();
delay(wait);
for (int j = 0; j < num; j++)
{
pixels.setPixelColor(j, 0, 255, 0);
}
pixels.show();
delay(wait);
}
void setup()
{
pixels.begin();
pixels.setBrightness(50);
}
void loop()
{
NeoBlink(NUMPIXELS, 500);
}
```
- done
movie
![test1.gif](../images/week10/test1.gif)
**Test 2 : Fading mode**
```jsx
/*
NeoPixel LEDs
modified on 7 May 2019
by Saeed Hosseini @ Electropeak
https://electropeak.com/learn/
*/
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
#define PIN 6
#define NUMPIXELS 8
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 500 // Time (in milliseconds) to pause between pixels
void NeoFade(int FadeSpeed)
{
int fspeed;
for (int i = 0; i < NUMPIXELS; i++) { pixels.setPixelColor(i, 165, 242, 243); } for (int j = 130; j > 0; j=j-10)
{
pixels.setBrightness(j);
pixels.show();
delay(FadeSpeed);
}
}
void setup() {
pixels.begin();
}
void loop() {
NeoFade(300);
}
```
// the setup function runs once when you press reset or power the board
- done
movie
![test2.gif](../images/week10/test2.gif)
Test 3 : Rainbow
- Design how to light by [Neo Pixel Effect Generator](https://adrianotiger.github.io/Neopixel-Effect-Generator/)
click “add led strip”
![rainbow2.png](../images/week10/rainbow2.png)
click the led image and setting it
![rainbow3.png](../images/week10/rainbow3.png)
Add effect Rainbow
![rainbow4.png](../images/week10/rainbow4.png)
set animation and color
![rainbow5.png](../images/week10/rainbow5.png)
Generate code
![rainbow6.png](../images/week10/rainbow6.png)
- write the program which is generated
```jsx
#include <Adafruit_NeoPixel.h>
class Strip
{
public:
uint8_t effect;
uint8_t effects;
uint16_t effStep;
unsigned long effStart;
Adafruit_NeoPixel strip;
Strip(uint16_t leds, uint8_t pin, uint8_t toteffects, uint16_t striptype) : strip(leds, pin, striptype) {
effect = -1;
effects = toteffects;
Reset();
}
void Reset(){
effStep = 0;
effect = (effect + 1) % effects;
effStart = millis();
}
};
struct Loop
{
uint8_t currentChild;
uint8_t childs;
bool timeBased;
uint16_t cycles;
uint16_t currentTime;
Loop(uint8_t totchilds, bool timebased, uint16_t tottime) {currentTime=0;currentChild=0;childs=totchilds;timeBased=timebased;cycles=tottime;}
};
Strip strip_0(8, 6, 8, NEO_GRB + NEO_KHZ800);
struct Loop strip0loop0(1, false, 1);
//[GLOBAL_VARIABLES]
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
//Your setup here:
strip_0.strip.begin();
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
//Your code here:
strips_loop();
}
void strips_loop() {
if(strip0_loop0() & 0x01)
strip_0.strip.show();
}
uint8_t strip0_loop0() {
uint8_t ret = 0x00;
switch(strip0loop0.currentChild) {
case 0:
ret = strip0_loop0_eff0();break;
}
if(ret & 0x02) {
ret &= 0xfd;
if(strip0loop0.currentChild + 1 >= strip0loop0.childs) {
strip0loop0.currentChild = 0;
if(++strip0loop0.currentTime >= strip0loop0.cycles) {strip0loop0.currentTime = 0; ret |= 0x02;}
}
else {
strip0loop0.currentChild++;
}
};
return ret;
}
uint8_t strip0_loop0_eff0() {
// Strip ID: 0 - Effect: Rainbow - LEDS: 8
// Steps: 8 - Delay: 20
// Colors: 3 (255.0.0, 0.255.0, 0.0.255)
// Options: rainbowlen=8, toLeft=true,
if(millis() - strip_0.effStart < 20 * (strip_0.effStep)) return 0x00;
float factor1, factor2;
uint16_t ind;
for(uint16_t j=0;j<8;j++) {
ind = strip_0.effStep + j * 1;
switch((int)((ind % 8) / 2.6666666666666665)) {
case 0: factor1 = 1.0 - ((float)(ind % 8 - 0 * 2.6666666666666665) / 2.6666666666666665);
factor2 = (float)((int)(ind - 0) % 8) / 2.6666666666666665;
strip_0.strip.setPixelColor(j, 255 * factor1 + 0 * factor2, 0 * factor1 + 255 * factor2, 0 * factor1 + 0 * factor2);
break;
case 1: factor1 = 1.0 - ((float)(ind % 8 - 1 * 2.6666666666666665) / 2.6666666666666665);
factor2 = (float)((int)(ind - 2.6666666666666665) % 8) / 2.6666666666666665;
strip_0.strip.setPixelColor(j, 0 * factor1 + 0 * factor2, 255 * factor1 + 0 * factor2, 0 * factor1 + 255 * factor2);
break;
case 2: factor1 = 1.0 - ((float)(ind % 8 - 2 * 2.6666666666666665) / 2.6666666666666665);
factor2 = (float)((int)(ind - 5.333333333333333) % 8) / 2.6666666666666665;
strip_0.strip.setPixelColor(j, 0 * factor1 + 255 * factor2, 0 * factor1 + 0 * factor2, 255 * factor1 + 0 * factor2);
break;
}
}
if(strip_0.effStep >= 8) {strip_0.Reset(); return 0x03; }
else strip_0.effStep++;
return 0x01;
}
```
## Gallery
- done
movie
---
## try to set it up by using my own breakout board →in this page
- replace the arduino UNO to ATtiny 3216 breakout board which I built before
![breakout_led.jpeg](../images/week10/breakout_led.jpeg)
- take advantage of the sample code in arduino : Example > Tiny NeoPixcel > simple
![code.png](../images/week10/code.png)
- edit code
```jsx
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library
#include <tinyNeoPixel.h>
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN 6
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 8
// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
tinyNeoPixel pixels = tinyNeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 500; // delay for half a second
void setup() {
pixels.begin(); // This initializes the NeoPixel library.
}
void loop() {
// For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
for (int i = 0; i < NUMPIXELS; i++) {
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(0, 150, 0)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
```
- how to light : fade-in
```jsx
/*
NeoPixel LEDs
modified on 7 May 2019
by Saeed Hosseini @ Electropeak
https://electropeak.com/learn/
*/
#include <tinyNeoPixel.h>
#define PIN 6
#define NUMPIXELS 8
tinyNeoPixel pixels = tinyNeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
// int delayval = 500; // delay for half a second
// #define DELAYVAL 500 // Time (in milliseconds) to pause between pixels
void NeoFade(int FadeSpeed)
{
int fspeed;
for (int i = 0; i < NUMPIXELS; i++) { pixels.setPixelColor(i, 165, 242, 243); } for (int j = 1; j < 255; j=j+2)
{
pixels.setBrightness(j);
pixels.show();
delay(FadeSpeed);
}
}
void setup() {
pixels.begin();
pixels.clear(); // Set all pixel colors to 'off'
}
void loop() {
NeoFade(50);
}
```
- done
![breakout_led_result.jpeg](../images/week10/breakout_led_result.jpeg)
## measure the power consumption of an output device
- insert a registor of 1 ohm before Neo Pixel LED as a shunt registor
- edit code which come to illuminate LED the blightest (parameter is 255 )
```jsx
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// Released under the GPLv3 license to match the rest of the
// Adafruit NeoPixel library
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN 6 // On Trinket or Gemma, suggest changing this to 1
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 8 // Popular NeoPixel ring size
// When setting up the NeoPixel library, we tell it how many pixels,
// and which pin to use to send signals. Note that for older NeoPixel
// strips you might need to change the third parameter -- see the
// strandtest example for more information on possible values.
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 500 // Time (in milliseconds) to pause between pixels
void setup() {
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
// Any other board, you can remove this part (but no harm leaving it):
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
// END of Trinket-specific code.
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
}
void loop() {
pixels.clear(); // Set all pixel colors to 'off'
// The first NeoPixel in a strand is #0, second is 1, all the way up
// to the count of pixels minus one.
for (int i = 0; i < NUMPIXELS; i++) { // For each pixel...
// pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
// Here we're using a moderately bright green color:
pixels.setPixelColor(0, pixels.Color(255, 255, 255));
pixels.setPixelColor(1, pixels.Color(255, 255, 255));
pixels.setPixelColor(2, pixels.Color(255, 255, 255));
pixels.setPixelColor(3, pixels.Color(255, 255, 255));
pixels.setPixelColor(4, pixels.Color(255, 255, 255));
pixels.setPixelColor(5, pixels.Color(255, 255, 255));
pixels.setPixelColor(6, pixels.Color(255, 255, 255));
pixels.setPixelColor(7, pixels.Color(255, 255, 255));
pixels.show(); // Send the updated pixel colors to the hardware.
// delay(DELAYVAL); // Pause before next pass through loop
}
}
```
- take measurement the potential difference between shunt registors by a multimeter
![registor_light_255.jpeg](../images/week10/registor_light_255.jpeg)
275.4 mV
V=IR
∴ I=V/R=275.4/1 =275.4mA [1]
- Reduce light intensity by half ( parameter is 128 )
```jsx
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// Released under the GPLv3 license to match the rest of the
// Adafruit NeoPixel library
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN 6 // On Trinket or Gemma, suggest changing this to 1
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 8 // Popular NeoPixel ring size
// When setting up the NeoPixel library, we tell it how many pixels,
// and which pin to use to send signals. Note that for older NeoPixel
// strips you might need to change the third parameter -- see the
// strandtest example for more information on possible values.
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 500 // Time (in milliseconds) to pause between pixels
void setup() {
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
// Any other board, you can remove this part (but no harm leaving it):
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
// END of Trinket-specific code.
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
}
void loop() {
pixels.clear(); // Set all pixel colors to 'off'
// The first NeoPixel in a strand is #0, second is 1, all the way up
// to the count of pixels minus one.
for (int i = 0; i < NUMPIXELS; i++) { // For each pixel...
// pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
// Here we're using a moderately bright green color:
pixels.setPixelColor(0, pixels.Color(128, 128, 128));
pixels.setPixelColor(1, pixels.Color(128, 128, 128));
pixels.setPixelColor(2, pixels.Color(128, 128, 128));
pixels.setPixelColor(3, pixels.Color(128, 128, 128));
pixels.setPixelColor(4, pixels.Color(128, 128, 128));
pixels.setPixelColor(5, pixels.Color(128, 128, 128));
pixels.setPixelColor(6, pixels.Color(128, 128, 128));
pixels.setPixelColor(7, pixels.Color(128, 128, 128));
pixels.show(); // Send the updated pixel colors to the hardware.
// delay(DELAYVAL); // Pause before next pass through loop
}
}
```
- take measurement the potential difference between shunt registors by a multimeter again
![registor_light_128.jpeg](../images/week10/registor_light_128.jpeg)
139.8 mV
V=IR ∴ I=V/R=139.8/1 =139.8mA [2]
![](../images/sample-photo.jpg)
- calcurate the ratio of [1] to [2]
## Video
275.4 / 139.8= **1.969**
### From Vimeo
→By doubling the light intensity, the current is almost doubled.
<iframe src="https://player.vimeo.com/video/10048961" width="640" height="480" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
<p><a href="https://vimeo.com/10048961">Sound Waves</a> from <a href="https://vimeo.com/radarboy">George Gally (Radarboy)</a> on <a href="https://vimeo.com">Vimeo</a>.</p>
- calcurate Power Consumption
### From Youtube
P255=I*V =275.4mV *275.4mA = **75.85mW [3]**
<iframe width="560" height="315" src="https://www.youtube.com/embed/jjNgJFemlC4" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
P128 = I*V =139.8mV *139.8 mA = **19.54mW [4]**
## 3D Models
calcurate the ratio of [3] to [4] which answer is 75.8 / 19.5 =**3.88**
<div class="sketchfab-embed-wrapper"><iframe width="640" height="480" src="https://sketchfab.com/models/658c8f8a2f3042c3ad7bdedd83f1c915/embed" frameborder="0" allow="autoplay; fullscreen; vr" mozallowfullscreen="true" webkitallowfullscreen="true"></iframe>
## What I learned in this week
<p style="font-size: 13px; font-weight: normal; margin: 5px; color: #4A4A4A;">
<a href="https://sketchfab.com/models/658c8f8a2f3042c3ad7bdedd83f1c915?utm_medium=embed&utm_source=website&utm_campaign=share-popup" target="_blank" style="font-weight: bold; color: #1CAAD9;">Dita&#39;s Gown</a>
by <a href="https://sketchfab.com/francisbitontistudio?utm_medium=embed&utm_source=website&utm_campaign=share-popup" target="_blank" style="font-weight: bold; color: #1CAAD9;">Francis Bitonti Studio</a>
on <a href="https://sketchfab.com?utm_medium=embed&utm_source=website&utm_campaign=share-popup" target="_blank" style="font-weight: bold; color: #1CAAD9;">Sketchfab</a>
</p>
</div>
[individual page](https://fabacademy.org/2022/labs/kannai/students/yukiya-yamane/assignments/week11/)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment