Hello All,
I have a project that is working very well when I am programming and plugged in via USB. I send some data from a bluetooth enabled device to an arduino leonardo with a bluetooth radio. The data is 6 bytes, and the code to send and receive seems to work perfectly when the arduino is powered via a USB cable.
The idea is that this arduino node will be battery powered. I am using a 9v battery for now, but eventually would change to something rechargeable, prob 3.7v lipo. I understand the capacities, currents, of these two, and the 5v supply from my laptop are all different.
When I power the arduino node from the 9v, the system does not respond to the incoming bluetooth messages (well, with simpler code, when I am just sending one byte at a time things work, but now I want to be able to send a data packet). The bluetooth module signals to me that it is connected and my application sending the bluetooth commands verifies that it is connected to the bluetooth module. I have a switch(case) structure that runs different code based on the incoming message, but I only ever hit the default case, meaning that the arduino is not understanding the incoming message. The first byte of the message is the program to run. If I look at the serial monitor while connected via USB, this comes in beautifully. I've omitted the specific program codes for brevity, but at the moment I am changing the blinking rate of an LED based on the incoming program byte.
Again, working beautifully when powered via USB, not so much when connected via battery. Is the communication affected by the battery voltage? Would this cause the communications to get out of sync? What are some strategies to deal with this? Would adding capacitors to my circuit (not much of a circuit, just everything plugged into the arduino pins, battery + into Vin). Any help would be greatly appreciated!
Here is the basic code on the arduino:
byte data[6];
byte prog = 0;
void setup()
{
Serial.begin(9600);
Serial1.begin(38400); //start bluetooth
}
void loop() {
if (Serial1.available() >= 6) // this will only be true if there are at least 9 bytes to read
{
for (int i=0; i <=5 ; i++)
{
data[i] = Serial1.read();
}
prog = data[0];
/*
Serial.print(data[0]);
Serial.print(",");
Serial.print(data[1]);
Serial.print(",");
Serial.print(data[2]);
Serial.print(",");
Serial.print(data[3]);
Serial.print(",");
Serial.print(data[4]);
Serial.print(",");
Serial.println(data[5]);
*/
}
program(prog);
}
void program(byte p )
{
switch(p)
{
case 1:
//do program 1
break;
case 2:
//do program 2
break;
case 3:
//do program 3
break;
case 4:
//do program 4
break;
case 5:
//do program 5
break;
case 6:
//do program 6
break;
default:
//do default program
break;
}
}