Pages: [1]   Go Down
Author Topic: [Solved] I2C + Serial on Mega ?  (Read 442 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I try to use a SRF10 sonar with a Arduino Mega board. I tried this code ( http://arduino.cc/en/Tutorial/SFRRangerReader )  and also some other codes I found on Internet, but I always have the same problem...

My code is running (the sonar is emitting ultrasounds and I can make a DEL blink) but I don't have any access to the USB Serial interface.

Indeed, my card simply don't show up on my computer immediately after the upload (ie /dev/TTYACM0 is not created) and I can't get any Serial.

However, normally Serial works fine. It is a problem that appear when I use Wire.h and it appears as soon as I read data thanks to WIre (immediately after upload, the card doesn't respond with the Serial Monitor).


I didn't find any doc about this problem. Do you know how to deal with it ?

Thanks !
« Last Edit: February 23, 2013, 09:37:14 am by Phyks » Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4682
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

From the /dev/ttyACM0 I guess you have a Arduino Mega2560 and not an Arduino Mega (which uses a ATmega1280 processor and an FTDI chip for the USB to serial adaption).

On the Arduino Mega2560 the communication with the PC is done by the ATmega16U2 coprocessor also on the board. When you use the Wire library you just change the hardware state of the main processor and not the state of the coprocessor. The only reason I can see for your symptoms is that the coprocessor gets reset. My guess is that the power supply doesn't deliver enough current. What do you access with the Wire library, what device is connected to the I2C and how have you connected it?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In fact, I have a Mega2560.
I try accessing a Sonar. Power comes from USB and there's only the arduino board and the sonar connected.

I don't think it is a board problem and Wire and Serial seems to work fine, but not together.

More info about further investigations I did :
I tested this code : http://arduino.cc/en/Tutorial/SFRRangerReader (which should work)

This part :
Code:
Wire.beginTransmission(112); // transmit to device #112 (0x70)
                               // the address specified in the datasheet is 224 (0xE0)
                               // but i2c adressing uses the high 7 bits so it's 112
  Wire.write(byte(0x00));      // sets register pointer to the command register (0x00) 
  Wire.write(byte(0x50));

works fine and I still have Serial if I only execute this part.

But as soon as I execute Wire.endTransmission() after this code (end of step 1), I loose Serial communication.

I tested the return value of Wire.endTransmission() with a DEL but this function seems to return 0, so it seems it executed just fine...
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45982
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
But as soon as I execute Wire.endTransmission() after this code (end of step 1), I loose Serial communication.
You loose serial communication, or the method() blocks waiting for an event to happen?

Quote
I tested the return value of Wire.endTransmission() with a DEL
How?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In fact, I don't know exactly what is happening. But on Linux, /dev/TTYACM* disappears and on Windows, the card doesn't appear anymore in the devices manager.

I think Wire.endTransmission doesn't block because if I had a sample code to make a DEL blink after this code, the DEL blinks (but I still don't have a serial communication).

To test the return value of Wire.endTransmission, I did
Code:
int error = Wire.endTransmission()
and I made a test to make a DEL of a different color blink (RGB DEL) according to the value of error (0 or != 0). The DEL blinked for 0.
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4682
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How does the serial device (under Linux) return again? Is it a reset, a power cycle or just waiting some time?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It only returns after a hard reboot (so, after disconnecting the board from the computer and the power and connect it again).

Today, without any reason, it worked. I think it may be a bad pin and so a power problem...
Logged

Pages: [1]   Go Up
Jump to: