Voice Recognition + led strip, which AVR to choose? - Page 1
Forum section: electronics / projects

author: Moriambar
author_rank: Unknown
timestamp: June 21, 2023, 06:35:04 pm
content: Hi,I'm trying to miniaturize a "simple" project: it's basically an addressable led strip controlled via a VR module. The code compiled via arduino ide is around 6kB, so I tried an ATTiny 85, but, while it can manage some leds OR manage the VR module, it cannot manage the needed amount of leds (30) PLUS the VR module.Unfortunately, being a beginner, I don't know whether this is due to some lacking hardware capabilities (eg: too few timers, and all of those are used by the VR module) or the need for ram/memory. So I don't know which controller to use.Please do mind that I have to use AVRs since I depend upon the arduino core libraries. I thought (seeing perhaps a ram starvation) about the ATTINY167 or 1634. I won't need more than 10 and those are available in large enough quantities for this. Or do I need an ATMega (168 perhaps)? I'd rather not go the mega way if not needed.Thanks

author: sokoloff
author_rank: Super Contributor
timestamp: June 21, 2023, 06:39:07 pm
content: The RAM difference between addressing 2 ARGBs and 30 ARGBSs is only a few bytes.Are you saying you can do a couple of LEDs (in an addressable strip) and the VR, but can't do 30 and the VR?That is possible, but doesn't seem very likely.

author: Moriambar
author_rank: Unknown
timestamp: June 21, 2023, 06:51:36 pm
content: Quote from: sokoloff on June 21, 2023, 06:39:07 pmhi.Nope let me clarify:5 leds work.27 leds don't.VR+ 5 leds -> vr works but leds don't.EDIT: I left out, oops, that the leds do have a dynamic effect which does some "complex" calculationsHere's the code (it was tool generated)in setup we have:Code:float F = 50.0Inside a method in the loop we have:Code:for (uint8_t i = 0; i < NUM_LED; i++) {uint8_t ind = STEPS - ((strip_0.effStep - i) % STEPS);uint8_t col_ind = (uint8_t)((ind % STEPS) / F);float f1 = 1.0 - ((float)(ind % STEPS - col_ind * F) / F);float f2 = (float)((((int)(ind - col_ind * F)) % STEPS) / F);uint8_t next = (col_ind + 1) % 3;strip_0.strip.setPixelColor(i,f1 * (Curr_Effetto->colori.r) + f2 * (Curr_Effetto->colori.r),f1 * (Curr_Effetto->colori.g) + f2 * (Curr_Effetto->colori.g),f1 * (Curr_Effetto->colori.b) + f2 * (Curr_Effetto->colori.b));}if (strip_0.effStep >= STEPS) {strip_0.Reset();} else strip_0.effStep++;STEPS is defined to be 140EDIT: with an UNO everything works perfectlyalso the vr library is what takes the code from around 4.7k to ~6k-ish

author: Someone
author_rank: Super Contributor
timestamp: June 22, 2023, 12:03:38 am
content: Quote from: Moriambar on June 21, 2023, 06:35:04 pmQuote from: Moriambar on June 21, 2023, 06:51:36 pmWell there'syoura problem.

author: Moriambar
author_rank: Unknown
timestamp: June 22, 2023, 03:29:51 pm
content: Quote from: Someone on June 22, 2023, 12:03:38 amThanks, I'm refactoring the code to ints

author: Moriambar
author_rank: Unknown
timestamp: June 24, 2023, 12:16:45 pm
content: So, I changed the code a bit. I determined that:using just the led strip the code works fineusing both the strip and the VR module, only the latter workshere's my code, are you sure this can be done via an attiny85? Otherwise my question stands:which avr to choose, are ATTINY167 or 1634 adequate? I'm starting to think this is not a ram problem though, but either something wrong in the configuration or lack of "muscles" from the attiny85VCode:#include <VoiceRecognitionV3.h>#include <Adafruit_NeoPixel.h>#include <SoftwareSerial.h>#include <avr/delay.h>#define PIN_F PORTB2#define PIN_TX PORTB0#define PIN_RX PORTB1#define NUM_F 12#define DELAY 40#define TYPE NEO_GRB + NEO_KHZ800#define stopC (0)#define bluC (1)#define rossoC (2)#define arancioC (4)//struct Colore {uint8_t r;uint8_t g;uint8_t b;Colore(uint8_t rosso, uint8_t verde, uint8_t blu) {r = rosso;g = verde;b = blu;}Colore() {}};Adafruit_NeoPixel faccia = Adafruit_NeoPixel(NUM_F,PIN_F,TYPE);const Colore blu_1 = Colore(0, 100, 255);const Colore blu_2 = Colore(0, 0, 255);const Colore blu_3 = Colore(0, 0, 200);const Colore rosso_1 = Colore(255, 0, 0);const Colore rosso_2 = Colore(200, 0, 0);const Colore rosso_3 = Colore(200, 0, 100);const Colore a_1 = Colore(255, 150, 0);const Colore a_2 = Colore(255, 100, 0);const Colore a_3 = Colore(255, 50, 0);const Colore nero = Colore(0, 0, 0);struct Effetto {Colore colori;void set_colori(Colore f, Colore o) {colori = f;colori = o;}};volatile const Effetto spento;volatile const Effetto blu;volatile const Effetto rosso;volatile const Effetto giallo;volatile Effetto* effetto;VR mic(PIN_TX,PIN_RX);uint8_t buf;void setup() {spento.set_colori(nero,nero);blu.set_colori(blu_1,blu_3);rosso.set_colori(rosso_1,rosso_2);giallo.set_colori(a_1,a_2);effetto = &spento;faccia.begin();_delay_ms(100);mic.begin(9600);mic.clear();mic.load((uint8_t)stopC);mic.load((uint8_t)bluC);mic.load((uint8_t)rossoC);mic.load((uint8_t)arancioC);}void loop() {//Your code here:int ret;ret =0;ret = mic.recognize(buf,50);if(ret>0){switch(buf){case stopC:effetto=&spento;break;case rossoC:effetto=&rosso;break;case bluC:effetto=&blu;break;case arancioC:effetto=&giallo;break;}}effetta(0,NUM_F,&faccia);}void effetta(uint8_t ix, uint8_t num, Adafruit_NeoPixel* strip){Colore* c = &(effetto->colori);strip->fill(strip->Color(c->r,c->g,c->b),0,num);strip->show();_delay_ms(DELAY);}