-1

I 've made a pcb for a wireless ac light dimmer which is based on ATMega328p(Arduino Uno), 433 MHZ UART module for wireless communication, a TRIAC for ac load dimming and a MOC3020 for zero crossing detection for the arduino interrupt. Briefly, I have a transmitter which sends commands to the dimmer, the commands are two bytes; the first byte is an ID, the second byte is the dimming level which are 5 levels: 0%,25%,50%,75%,100%. I've programmed it to take about 2 seconds between each level. The serial communication baud rate is 9600 bps. My problem is that when I send a command during dimming time then the serial communication is totally lost. The thing is the Serial port can't read data while the interrupt is occurring. I thought of detaching the interrupt before reading data and reattaching it when its done but it didn't work. I've also tried to read the serial data inside the ISR but it didn't work too. Last thing I thought of is changing the baud rate but I didn't try it yet.

any suggestions to solve this problem.

Thanks

1 Answers1

0

I take it you are doing this with Arduino's Processing language, which is single threaded, so I would suspect it won't hit the point in execution where it notices the IRQ until it returns back to the main loop.

Here protothreads are suggested for this type of problem. I've also heard of running Golang code on an Arduino, which sounds like it would help for execution, but then you have to port/find all your libs for the radio. I haven't looked too far into it though.

Otherwise you would want a function, which does not block, that you can call each time through the loop to update the state of the dimmer (like a draw function). The thought here is that when it notices the IRQ you change the target state, and the "draw" function just takes a step towards the target state, then returns execution back to the main loop... Where you can notice the IRQ again to set a different target state.

Community
  • 1
  • 1