Not sure if this is the best forum to ask on, but trying to revive a closed many years old github issue thread is so far producing little results. Hopefully there are enough GRBL experts and AVR programming wizards here who might be able to help. Please see config.h support for pin for status light? · Issue #628 · grbl/grbl for background info In short I want my arduino uno / CNC mill to be able to easily show when the machine is in an ALARM state. Since I am new to GRBL and DIY CNC machines this added diagnostic help would be invaluable when an error occurs. Since commercial CNC machines usually have a large diagnostic LED beacon light having this functionality would be in line with professional machines. Having used the old code example from the above mentioned github thread I've managed to hack GRBL on a test UNO with a screw shield and an LED. I can get the port programming to reconfigure Analog 4 to be an output and can get the LED to light. The problem is that the code does not work as expected and either the LED remains always on regardless of state changes or completely off regardless of state changes. The intended behavior is for the LED to turn on when in an ALARM_STATE and off when not. I am not a programmer and can only hack code on occasion within the Arduino IDE, so this form of C or low level AVR coding is far out of my element. Still I'm pleased that I've at least managed to get the LED to light. Now i just need help to work out the bugs. here is the code in the protocol.c file: void protocol_exec_rt_system() { uint8_t rt_exec; // Temp variable to avoid calling volatile multiple times. //////////////////////// // ALARM LED CODE: #ifdef signal_light static uint8_t state=-1; if(state!=sys.state) { signal_light(init); if(state==-1) { // init } state=sys.state; if (state==STATE_ALARM) signal_light(on); else if (state==STATE_CYCLE) signal_light(off); else signal_light(off); } #endif //////////////////////// rt_exec = sys_rt_exec_alarm; // Copy volatile sys_rt_exec_alarm. here is the code for the cpu_map.h file: // Define flood and mist coolant enable output pins. #define COOLANT_FLOOD_DDR DDRC #define COOLANT_FLOOD_PORT PORTC #define COOLANT_FLOOD_BIT 3 // Uno Analog Pin 3 //#define COOLANT_MIST_DDR DDRC //#define COOLANT_MIST_PORT PORTC //#define COOLANT_MIST_BIT 4 // Uno Analog Pin 4 ////////////////// // Define ALARM LED OUTPUT #define SIGNAL_LIGHT_DDR DDRC #define SIGNAL_LIGHT_PORT PORTC #define SIGNAL_LIGHT_BIT 4 // Uno Analog Pin 4 #define signal_light(x) signal_light_##x() // #define signal_light(on) (SIGNAL_LIGHT_DDR |= (1<<SIGNAL_LIGHT_BIT), SIGNAL_LIGHT_PORT &= (1<<SIGNAL_LIGHT_BIT), SIGNAL_LIGHT_PORT |= (1<<SIGNAL_LIGHT_BIT) ) // #define signal_light_init() signal_light(off) #define signal_light_init() signal_light(off) #define signal_light(on) (SIGNAL_LIGHT_DDR |= (1<<SIGNAL_LIGHT_BIT), SIGNAL_LIGHT_PORT |= (1<<SIGNAL_LIGHT_BIT) ) // #define signal_light(off) //////////////////
Sorry, little off topic and not what you really want to do - but I would just use OpenBuilds CONTROL > Autostart macro that checks the feedback status we already pull > and sends requests to an ESP8266 running the light itself. - just an alternate approach
After much tinkering with the code i seem to have solved my own issue. In the end I had to get rid of the macro that was programmed in the example code. It also didn't hurt to learn a tiny bit about bit setting in C / C# programming. I'm still not a great programmer by any means, but I'm slightly better now. In the end the KISS method helped to simplify the code to where I both understood what the code was doing within the state machine AND worked as expected. So... go me! Yay! here is the working simplified code: for cpu_map.h file: // Define flood and mist coolant enable output pins. #define COOLANT_FLOOD_DDR DDRC #define COOLANT_FLOOD_PORT PORTC #define COOLANT_FLOOD_BIT 3 // Uno Analog Pin 3 //#define COOLANT_MIST_DDR DDRC //#define COOLANT_MIST_PORT PORTC //#define COOLANT_MIST_BIT 4 // Uno Analog Pin 4 ////////////////// // Define ALARM LED OUTPUT #define SIGNAL_LIGHT_DDR DDRC #define SIGNAL_LIGHT_PORT PORTC #define SIGNAL_LIGHT_BIT 4 // Uno Analog Pin 4 #define signal_light_init signal_light_off #define signal_light_on (SIGNAL_LIGHT_DDR |= SIGNAL_LIGHT_PORT |= (1<<SIGNAL_LIGHT_BIT) ) #define signal_light_off (SIGNAL_LIGHT_DDR |= SIGNAL_LIGHT_PORT &= ~(1<<SIGNAL_LIGHT_BIT) ) ////////////////// and for protocol.c file: // Executes run-time commands, when required. This function primarily operates as Grbl's state // machine and controls the various real-time features Grbl has to offer. // NOTE: Do not alter this unless you know exactly what you are doing! void protocol_exec_rt_system() { uint8_t rt_exec; // Temp variable to avoid calling volatile multiple times. rt_exec = sys_rt_exec_alarm; // Copy volatile sys_rt_exec_alarm. /////////////////////// // Define ALARM LED OUTPUT signal_light_init; //init LED in off state if (sys.state==STATE_ALARM) {signal_light_on;} else if (sys.state!=STATE_ALARM) {signal_light_off;} // else {signal_light_off;} ///////////////////////