Raspberry Pi control arduino a1mega

Hello, I thought I would share a project I have been working on for work. I’m using a raspberry pi to send commands to an arduino atmega 2560 which either turns on/off relays or takes an analog reading.

The raspberry pi software is written in C++ using QT Creator. It starts through user input then sends single to turn on X relay and sends command to read an analog channel at set increments. When designated time is finished it send command to turn on x relay then kills the timer.

The arduino software is very basic. simple case statement and either reads or turns on/off relay based on command.

DISCLAIMER: Both pieces of code are poorly written. I needed this working immediately so I hacked it to heck and back. I will be cleaning it up soon, but thought this may help somebody wanting to communicate with an arduino using c++ on the raspberry pi.

GITHUB: GitHub - aelmendorf/Reliability-Stress-System: Control for 8 current driver boards with 24 drivers/board

Thanks for reading, hope this helps someone!

SlotTimer.cpp (12.3 KB)

SlotTimer.h (3.63 KB)

Relay_Command_Control_noUSB.ino (2.89 KB)

One easy and possible fix is that you never update inputDone (which is false by default). This is because serialEvent() is NEVER CALLED in the loop() function. This means the if statement in the loop() function never executes, no matter what. You also never take in serial data since serialEvent() is never called.

Power_Broker: One easy and possible fix is that you never update inputDone (which is false by default). This is because serialEvent() is NEVER CALLED in the loop() function. This means the if statement in the loop() function never executes, no matter what. You also never take in serial data since serialEvent() is never called.

It may appear that way but serialEvent is a special case. It is called for you from main. See this (slightly confusing) tutorial: SerialEvent

wildbill: It may appear that way but serialEvent is a special case. It is called for you from main. See this (slightly confusing) tutorial: SerialEvent

wildbill is correct, serialEvent is an interupt routine.