Go Down

Topic: Pro Micro conflict with timers and serial.print (Read 391 times) previous topic - next topic


I am trying to get my own version of Luc Small's weather station decoder working on a Chinese Arduino Micro Pro (5V). I have it working fine on a Uno R3. I have adapted the code to the Micro Pro, changing the ports, and have it working sort of. It works in picking up my weather station transmissions and decoding them, the problem I have is printing to the serial monitor, where it prints the first 63 characters each transmission and then cuts off mid word.

{"Sensor_ID":"A4E", "humidity":82, "temperature":10.9, "wind_sp

a normal transmission would look something like this:
{"Sensor_ID":"A4E", "humidity":83, "temperature":11.0, "wind_speed":0.0, "wind_speed_max":0.0, "wind_dir":0.0, "rain_sum":506.4, "validity":1, "full_message":"A4 E1 FE 53 0 0 6 98 0 C8 "}↵

It keeps receiving packages, and just keeps printing the first 63 characters of each serial transmission.

My full code is here: https://www.dropbox.com/s/aeblbo71r95bio5/BetterWH2_PG_v20_ProMicro.ino?dl=0

I have tried a whole heap of troubleshooting, and believe I have narrowed the problem down to some sort of conflict between the timer and the serial output. The code below is a simple test of this where the timer is set up and I try to print text to the serial monitor. The "Serial Started" text comes through, but then the  pro micro freezes up and all the onboard leds turn on solid.

If I comment out the TIMSK1 |= (1 << OCIE1A); line, the code works fine, and the text comes through on the serial monitor as expected.

Can anyone shed light on why this wouldn't work?

#define COUNTER_RATE 1600

void setup() {

  while (!Serial) ;  // while the serial stream is not open, do nothing:
  Serial.println("Serial started");
  noInterrupts();           // disable all interrupts
  TCCR1A = 0;
  TCCR1B = 0;
  TCCR1C = 0;
  TCNT1  = 0;

  OCR1A = COUNTER_RATE;     // compare match register
  TCCR1B |= (1 << WGM12);   // CTC mode
  TCCR1B |= (1 << CS10);    // 256 prescaler
  TIMSK1 |= (1 << OCIE1A);  // enable timer compare interrupt0
  interrupts();  // enable interrupts


void loop() {
      Serial.print("I just want to print all this text out to the serial monitor");


When I try to follow your link, I get:
The proxy server is refusing connections
Now, I know that this is a problem on my end (my company's proxy server is the one refusing the connection). But, if you followed the rules, and attached your code HERE, I could see it.
The art of getting good answers lies in asking good questions.


Thanks for trying already. Full code is attached below. Cheers. :-)


You are trying to print while interrupts are disabled. Don't do that.

As a separate comment, I don't know what your ISR is doing but there seems to an awful lot of code in it. Can't most of that be taken out of the ISR and handled elsewhere?

Two or three hours spent thinking and reading documentation solves most programming problems.


If I comment out the TIMSK1 |= (1 << OCIE1A); line, the code works fine, and the text comes through on the serial monitor as expected.
Since enabling the Output Compare Interrupt causes a problem, I would say your problem is probably in that ISR.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp


Guys, thanks for your help. All is working. I removed the interrupt disable/enable around the printing and that sorted it.

Also, I figured out, the mini sketch I had created to test the timers wasn't working because there was no ISR in the sketch. I added an empty ISR and wallah, all good.

Thanks again!

Go Up