Arduino - lorenzo-campana/bpm GitHub Wiki
Arduino is a simple to use and inexpensive microcontroller. For our project we will use an Arduino UNO; a very useful and well put together first step guide is available on the Arduino official site.
NB: the Arduino boards are not industrial microcontrollers, so they aren't completely reliable. They are inexpensive and tailored toward hobbyist. That said, they are really cheap and simple to program, so we used an Arduino Uno to create a prototype project, a proof of concept that a microcontroller can be use for our needs. For all this reason the final project will use an Infineon XMC 4700 microcontroller.
Arduino serial communication
The following code is an example on how to implement a serial communication between the Arduino and a Raspberry Pi with Epics installed and configured. To function properly, the Arduino must be connected to a Pi with a protocol configured, as explained in this guide.
String input = "";
int parameter;
void setup() {
Serial.begin(115200);
}
void loop () {
while (Serial.available()>0){
char lastRecvd = Serial.read();
if (lastRecvd == '\n') {
switch (input[0]) {
case 'P': // A write command has come in
input = input.substring(1,input.length());
parameter=input.toInt();
input = "";
break;
case 'R': // A read command has come in
Serial.print("something");
input = "";
break;
default:
break;
}
}
else { // Input is still coming in
input += lastRecvd;
}
}
}
In the setup()
we setup the serial comunication. In the loop()
the arduino scans the serial and record when something comes through. If it gets the letter "P" he will set the variable parameter
to what it received from the serial. If it receives a "R" it will write something to the serial bus.
This code, together with the proto file, connects the two records that we created to the serial, allowing the arduino to read and write them.