Hi guys, I think I need some help. I have started a project that just might revolutionize the peripheral world, if I can get it working. This is my last attempt at trying. I have 2 arduino lilypad main boards, which I can connect to my computer through FTDI. The 2 arduino boards both have 4 analog input devices connected to them on A0,A1,A2, and A3. I needed to synchronize the boards, and I've already failed once, but then I found I2C. So, I connected the two devices together at SCL,SDA, and Ground Pin. However I noticed that the ground pin also shares the analog input pins, which are connected in parallel. I am able to get the expected result by just measuring the analog signals on each board separately, but when I send the data from the SLAVE.ino over to the MASTER.ino the bending of the flex sensor analog inputs does not seem to correspond logically to what I would expect. I'm not sure if it's a coding problem or a hardware problem, or both. But I do think there might be a conflict of signals on the Ground Pin.
Any advice in the right direction would be greatly appreciated. I'm somewhat new to Arduino, but not to hobbyist electronics and programming.
For Clarification: I'm trying to send the analogRead() measurements over through I2C to the other arduino lilypad board. I do end up getting 4 readable values that look good enough, by splitting up the integer words into bytes, however when I bend the flex sensors the values do not seem to change in the way I would expect. Sometimes there is a 1 in the serial.println() , which doesn't make sense. When I measure the values simply using analogRead() on one board, I can see the value change between about 90 and 300, depending on if the flex sensor is bent. Usually if it's bent fully, I get about ~300 or so, and in a resting position about ~90. I've already had a failed attempt at synchronizing the boards using millis(), but I2C seems to work a lot better. I just need to be able to have the four analog inputs A0,A1,A2, and A3 sent over to the other board, so that I can send all the values through a Bluetooth Silver Mate from sparkfun.
Also, I should mention that I've noticed before when I'm trying to measure the analog inputs, that I have to measure them separately to get a correct measurement. Since they are basically connected over a parallel bus wire, I think that they have to be isolated. If you can figure out a way to measure them separately over I2C in the code, I think that just might work.
When I say I isolated them, I mean I did it programmatically by measuring them at separate times, but I2C seems to be a confounding factor in doing this, since I'm new to I2C.
I sense that you have used two micros, because you ran out of analogue input pins.
Common beginner's mistake.
A port expander is a better/easier solution.
Leo..
I2C does not allow you to isolate the ground. Because the data line must send data in both directions a conventional optoisolator cannot do the job.
However it should not be necessary if the project is as simple as you describe. Can you explain why you believe that the grounds should be separate?
If you do actually need separate grounds then Serial, either via the hardware Serial pins or SoftwareSerial may be a solution, with appropriate optoisolators.
MorganS:
I2C does not allow you to isolate the ground. Because the data line must send data in both directions a conventional optoisolator cannot do the job.
However it should not be necessary if the project is as simple as you describe. Can you explain why you believe that the grounds should be separate?
If you do actually need separate grounds then Serial, either via the hardware Serial pins or SoftwareSerial may be a solution, with appropriate optoisolators.
I do not believe the grounds should be separate(unless there is a conflict), I'm just saying that I needed to measure them separately programmatically. When I've tried to measure the analog signals without sending them over using I2C(just by doing analogRead() and outputting it to the serial monitor), I only get the data I expect if I use millis() and measure them at separate time intervals. I think that might be what is happening, and why I can't get a proper measurement when sending over I2C. I would use millis() to measure the time intervals and have them sent over I2C, but I'm not sure how that would work.
Since all of the flex sensors(analog devices) are on the same ground bus, and there is no set or enable wire. I think all of the devices may be getting read at one time, conflicting the data. It's either that or a conflict between the way the I2C is connected and the flex sensors(since they are both connected via GND).
Wawa:
I sense that you have used two micros, because you ran out of analogue input pins.
Common beginner's mistake.
A port expander is a better/easier solution.
Leo..
Sorry, I misread your reply. If the micros are referring to the Arduino Lilypad boards, then yes. I needed 5 analogue pins(I guess 10 in total), but I had to sacrifice one(or two) for the sake of I2C. Also, I just happened to have two arduino lilypads lying around, so I thought what the heck.
MarkT:
Your schematic shows V+ connected directly to ground, ie the board shorted out.
A correct schematic please, and post your code please.
All 4 analog inputs are connected to the analog inputs of the boards, along with being connected to a wire bus for positive and negative on each arduino.
Note: Some code is unused, and is only there for testing purposes.
// Slave(red)
#include <Wire.h>
int sensorValue[4];
byte hb[4];
byte lb[4];
void setup() {
Serial.begin(9600);
Wire.begin(8); // join i2c bus with address #8
Wire.onRequest(requestEvent); // register event
}
void loop() {
// REMBMBER TO ACCESS THE ANALOG SIGNALS SEPARATELY TO AVOID CONFUSION
sensorValue[0] = analogRead(A0);
sensorValue[1] = analogRead(A1);
sensorValue[2] = analogRead(A2);
sensorValue[3] = analogRead(A3);
} // end of loop
// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent(){
// break down words into bytes
hb[0]=highByte(sensorValue[0]);
lb[0]=lowByte(sensorValue[0]);
Wire.write(hb[0]);
Wire.write(lb[0]);
hb[1]=highByte(sensorValue[1]);
lb[1]=lowByte(sensorValue[1]);
Wire.write(hb[1]);
Wire.write(lb[1]);
hb[2]=highByte(sensorValue[2]);
lb[2]=lowByte(sensorValue[2]);
Wire.write(hb[2]);
Wire.write(lb[2]);
hb[3]=highByte(sensorValue[3]);
lb[3]=lowByte(sensorValue[3]);
Wire.write(hb[3]);
Wire.write(lb[3]);
}
MorganS:
If you do actually need separate grounds then Serial, either via the hardware Serial pins or SoftwareSerial may be a solution, with appropriate optoisolators.
I like the optoisolator idea, but it would require quite a bit of reworking the circuit. If I could just send the analog measurements discreetly at different intervals, that may work, too.
Grumpy_Mike:
To me your schematic looks wrong. You have no pull up resistors on the I2C lines and no pull up resistors on flex sensors.
Does I2C require resistors? I was successful in sending the data over. It's just that the analog wires are connected on the same ground wire conflicting the signal. They all get measured or read into the inputs at the same time. When I don't use I2C, and instead read the signals on serial monitor, I'm only able to do it if I read them with analog read() at separate times. The flex sensors seem to work and are made of a straw, 10,000ohm resistors,470ohm,photoresistor and led.
Grumpy_Mike:
To me your schematic looks wrong. You have no pull up resistors on the I2C lines and no pull up resistors on flex sensors.
If there were some way to send them over using I2C separately, at different times, it might work. I don't want to add a bunch of extra hardware. They are machine learning gloves by the way.
It's just that the analog wires are connected on the same ground wire conflicting the signal.
Yes they should be connected to the same ground, this is how it has to be. No this is not conflicting the signal.
Does I2C require resistors?
Yes. Sure with the internal pull up resistors in the Arduino you might get some functionality but they are only 35K or so and are not low enough. You need 4K7 pull-ups on a 5V bus system.
They are machine learning gloves by the way.
Oh great, tell us now and make earlier answers look stupid.
The flex sensors seem to work and are made of a straw, 10,000ohm resistors,470ohm,photoresistor and led.
So have you the schematic of this? A bit useless us trying to give any solutions until we know that. Have you at lest got a link to them or their data sheet.
Grumpy_Mike:
Yes they should be connected to the same ground, this is how it has to be. No this is not conflicting the signal.
Yes. Sure with the internal pull up resistors in the Arduino you might get some functionality but they are only 35K or so and are not low enough. You need 4K7 pull-ups on a 5V bus system.
Oh great, tell us now and make earlier answers look stupid.
So have you the schematic of this? A bit useless us trying to give any solutions until we know that. Have you at lest got a link to them or their data sheet.
As I said all the grounds should be connected together, and if their is any interaction between the grounds you have not wired it up like your schematic suggests you have. There is no need for a pull up on the analogue inputs. But you need them on the I2C lines like Tom showed.
Grumpy_Mike:
Oh great, tell us now and make earlier answers look stupid.
I don't believe any of the answers were stupid. I appreciate all of the help. I think if I isolate the requests from the master with millis() time intervals, that may work.
As I said all the grounds should be connected together, and if their is any interaction between the grounds you have not wired it up like your schematic suggests you have. There is no need for a pull up on the analogue inputs. But you need them on the I2C lines like Tom showed.
I think you are right, but the flex sensors will get read all at the same time, correct? Unless I isolate them programmatically? There in lies the real problem.