I need to connect 5 to 7 pro - mini's and I would like to pass the data in a "bucket brigade" style. I need to use pro - mini's because of the size restrictions. Each arduino needs to pass the data back and fro because the connections between they can be change with the system powered down. Once the system is powered up, we need to know the order in which they are configured. The speed can be very slow, 1-3 seconds. I tried to use the follow code and it worked, but very spotting. Do you think using "Altsoftserial" and the pro - mini's UART would give me better performance.
/*
This code is meant for the compiler. talks to the PC/Mac and the first arduino.
ID itself with a "H" and gives a state for the compile button
*/
#include <SoftwareSerial.h>
SoftwareSerial portOne = SoftwareSerial(4,5); //D4 is the RX for the softport
char inByte;
char outByte;
char idByte = 'H';
char stateByte = '1';
char recByte;
char pollByte = 'p';
int led = 13;
void setup()
{
// Open serial communications and wait for ports to open:
Serial.begin(9600);
portOne.begin(1200);
pinMode(led, OUTPUT);//.staute LED
}
void loop()
{
if (Serial.available() > 0)
{
inByte = Serial.read();
Serial.println(inByte);
if (inByte == pollByte)
{
Serial.print(idByte);
Serial.print(stateByte);
portOne.write(inByte);
delay(5);
digitalWrite(led, HIGH);
}
}
portOne.listen();
delay(5);
if (portOne.available() > 0)
{
recByte = portOne.read();
Serial.write(recByte);
Serial.println();
}
}
// code for the first following arduino
/*
Main blox sends polling ASCII. First blox receives poll and sends a ASCII
and state back to Main blox, then sends polling ASCII to next blox. passes
the receiving ASCII and state back to the main blox.
*/
#include <SoftwareSerial.h>
// Up stream port
SoftwareSerial portIn = SoftwareSerial(2,3);
// Down stream port
SoftwareSerial portOut = SoftwareSerial(4,5);
char inByte;
char outByte;
char idByte = 'B';
char stateByte = 1;
char recByte;
char pollByte = 'p';
int led = 13;
void setup()
{
portIn.begin(1200);
portOut.begin(1200);
pinMode(led, OUTPUT);
}
void loop()
{
portIn.listen();
delay(5);
if (portIn.available() > 0) {
inByte = portIn.read();
if (inByte == pollByte)
{
portIn.write(idByte);
delay(5);
portIn.write(stateByte);
delay(5);
portOut.write(inByte);
delay(5);
digitalWrite(led, HIGH);
}}
portOut.listen();
delay(5);
if (portOut.available() > 0) {
recByte = portOut.read();
portIn.write(recByte);
delay(5);
}
}
Blox_smallB.ino (1.07 KB)