These are chat archives for esp8266/Arduino

14th
May 2016
Clemens Kirchgatterer
@everslick
May 14 2016 13:31
https://github.com/everslick/genesys -> A firmware development framework for ESP8266 based on esp-arduino-core.
any feedback is appreciated very much!
M0ebiu5
@M0ebiu5
May 14 2016 14:59
How do multiple tickers work? Does the os wait until i return from the ticker callback, or are the callbacks fired "simultaneously"?
Clemens Kirchgatterer
@everslick
May 14 2016 15:21
i'm pretty sure you have to return from the previous timer callback to allow the next to run. i don't think the callbacks are run directly from an ISR
M0ebiu5
@M0ebiu5
May 14 2016 15:29
ok - but it would be interesting to know, where the ticker callbacks are called. At the end or beginning of the main loop, or also during delay or yield,...?
Me No Dev
@me-no-dev
May 14 2016 15:49
They are interrupts but there is no nested interrups on esp so they go one after another. That is the reson why you should never delay or yield in them
Michael Miller
@Makuna
May 14 2016 16:00
@M0ebiu5 About your progmem issue, your example is strange as you are setting up an array of unsigned 32 bit integers but you are trying to read only 16 bits from them. the read word is 16 bits. I avoid the use of "unsigned int" as visually its ambiguous to the size and use the new standards of uint32_t instead.
Michael Miller
@Makuna
May 14 2016 16:09
@M0ebiu5 Please confirm for me, if you look at the compile output, there is a definition for ets like...
-D__ets__
M0ebiu5
@M0ebiu5
May 14 2016 16:32
xtensa-lx106-elf-g++" -D__ets__
@Makuna thanks for the hint with the integer - the code is from an atmega and there the uint is 2 bytes = word
M0ebiu5
@M0ebiu5
May 14 2016 16:44
@me-no-dev so the ticker callback is called from an isr?
Michael Miller
@Makuna
May 14 2016 17:08
@M0ebiu5 This works for me, its interesting that your sample does not work for me either
const uint16_t PROGMEM pwmTable[]   = {42,43};
unsigned int i = 0;

void setup() {
 Serial.begin(115200);
 while (!Serial);
 Serial.println("Startup...");
}

void loop() {
  delay(5000);
  Serial.print(i);
  Serial.print(" = ");

  uint16_t readvalue = pgm_read_word(pwmTable + i);
  i = (i+1) % (sizeof(pwmTable) / sizeof(pwmTable[0]));

  Serial.println(readvalue);
  Serial.flush();
}
M0ebiu5
@M0ebiu5
May 14 2016 17:15
@Makuna it's the type of the array - i only changed it from unsigned integer to uint16_t and it works - thanks for your help!
Michael Miller
@Makuna
May 14 2016 17:24
It still should not be having an issue, its just memory, reading 16 bits should not be an issue; but it is as this also doesn't work...
const uint32_t  pwmTable[] PROGMEM  = {42,43};
unsigned int i = 0;

void setup() {
 Serial.begin(115200);
 while (!Serial);
 Serial.println("Startup...");
}

void loop() {
  delay(5000);
  Serial.print(i);
  Serial.print(" = ");

  uint32_t readvalue = pgm_read_word(pwmTable + i);
  i = (i+1) % (sizeof(pwmTable) / sizeof(pwmTable[0]));

  Serial.println(readvalue);
  Serial.flush();
}
but if you change this single line it works
  uint16_t readvalue = pgm_read_word(pwmTable + i);
M0ebiu5
@M0ebiu5
May 14 2016 17:36
good to know - but a 4 byte pwm value is a little overkill for my led driver :) I have to check now the issue with the large integer in my code - the change of the integer size doesn't look logical for me. This will be an issue for more people coming from "normal" arduino...
Michael Miller
@Makuna
May 14 2016 17:54
I created esp8266/Arduino#2028 to track the issue; as it should not have caused a problem.
@M0ebiu5 integer size is the key reason NOT TO USE them. Its documented in C/C++ that int is sized to the processor native size, most AVR are 8bit, Esp and Arm are 32bit. The real strange thing here is that "word" is documented as 16bits; but if you look at documents on CPUs, word is often referred to as the native size of the cpu element (8 bit/32bit). I hate that C/C++ did this; but this is why everyone should use uint32_t (8,16,32,64) and int32_t types instead.
darshanraikanungo
@darshanraikanungo
May 14 2016 19:00
Help
M0ebiu5
@M0ebiu5
May 14 2016 19:01
Help is not available at this point...
darshanraikanungo
@darshanraikanungo
May 14 2016 19:04
I want ask a general questions
180,
180 coin is divided among 64 girls and boys. The sum of boys share and girl share are in ratio 5:4, but there individual share are 4:3. Find no. Of boys
Michael Miller
@Makuna
May 14 2016 19:24
@darshanraikanungo what does that have to do with Esp8266/Arduino?
M0ebiu5
@M0ebiu5
May 14 2016 20:08
I've tried to find out more about the ticker class - and my test crashed long before i had expected...
#include <Ticker.h>

Ticker tH;
Ticker tL;

void TimerCallback(int TimerId) {
for (byte i = 0; i < 254; i++) {
    Serial.print("CB:");
    Serial.print(TimerId);
    Serial.print(" cnt:");
    Serial.println(i);
//    yield();
  }
}
void setup() {
 Serial.begin(115200);
 Serial.println("Startup...");

 tL.attach_ms(6000, TimerCallback, 1);
 //tH.attach_ms(1200, TimerCallback, 2);
}
void loop() {
}
M0ebiu5
@M0ebiu5
May 14 2016 20:14
it crashes with only one ticker after 30 test lines with panic __yield. With yield() in the loop it crashes ironically when calling the yield function.
Gus Grubba
@dogmaphobic
May 14 2016 20:35
Isn’t the ticker an interrupt? Can you safely use Serial.print from within an interrupt handler?
M0ebiu5
@M0ebiu5
May 14 2016 20:43
It looks like that - but i couldn't find more info about the ticker. I only know i can have as many as i want - but even 1 is too much for me...
Me No Dev
@me-no-dev
May 14 2016 23:48
so in your TimerCallback you try to send about 2.5KB through the Serial before you release the Ticker
that takes roughly 175ms at 115200 Serial Baud
which is way more time that you can spend into an interrupt routine before the watchdog kicks you and kills the sketch
actually it takes more time but even that is enough (did not take into account the start and stop bits)