4
\$\begingroup\$

All -

Why does my Arduino 2560 report text that looks like this:

I©ä

I©ä

!11<]=I1)!11<]=I1)!11<]=I1!11<]=I1)!11<]=I1©ä é ©ä

I©ä

I©ä

I©ä

Every time I execute "spi_dev_test" from my raspberry pi?

I have been trying to follow the instructions on this website :

http://mitchtech.net/raspberry-pi-arduino-spi/

But these instructions are for an Arduino Uno whereas I am using an Arduino 2560.

I looked up documentation for the 2560 here:

http://www.jameco.com/Jameco/Products/ProdDS/2121113.pdf

and it has indicated the SPI pins are SPI: 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS).

I wired them like so:

RaspberryPi-MOSI ======>> 51(MOSI) on 2560

RaspberryPi-MISO ======>> 50(MISO) on 2560

RaspberryPi-CSO ======>> 52(SCK) on 2560

RaspberryPi-GND ======>> GND(just next to 53 on 2560).

According to the website I'm supposed to see "HELLO WORLD" output to the Arudino's serial monitor console.

The serial monitor baud rate is 115200. I have Tools >> Programmer set to "Arduino as ISP" but I've tried all other options with no success.

Would appreciate all / any advise.

\$\endgroup\$
  • \$\begingroup\$ Two things that should be done for pure software debugging: First, have the Arduino source it's own "hello" message to confirm the serial setup. Second, have it print out the hex value of received bytes rather than treat them as characters - trying to match these against possible communication errors will be easier. After that, break out the scope or logic analyzer, set the SPI sender to repeat one value in a tight loop, and see what is going wrong. Also make sure you are properly making the ATmega to Arduino pin designation translations in finding these pins. \$\endgroup\$ – Chris Stratton Jan 27 '14 at 23:03
5
\$\begingroup\$

Your captured outputs look like either a MISO-MOSI inverted connection, a baud rate mismatch or a sync problem. Sequence of steps to diagnose this:

  1. Check your serial settings: both sides should have the same configuration for data rate, parity, data bits and stop bits. 9600 baud/no parity/8 data bits/1 stop bit is a good starting point.
  2. Set up both devices to a low, identical baud rate e.g. 9600 baud, then increase it if 9600 works. Push it up till a possible bottleneck at serial handling code or cabling / connections shows up.
  3. Switch the MOSI and MISO lines at any one device - if you get nothing at all then switch them back.

If all the above steps fail, please update your question with results observed.

\$\endgroup\$
  • \$\begingroup\$ I tried to switch the MISO/MOSI pins and that generated no output so I switched them back. I decreased the "Serial.begin(9600)" command and re-flashed that to the Arduino, however looking at the "spidev_test.c" file there is no mention about baud rate. I am still receiving garbage but it looks different as the baud rate changes to higher numbers. The output I'm getting on the raspberry pi is: spi mode: 0 bits per word: 8 max speed: 500000 Hz (500 KHz) I'm also unclear how to set the parity on the raspberry pi or arduino mega. \$\endgroup\$ – user1068636 Oct 24 '12 at 4:49
  • \$\begingroup\$ Gibberish language change on bit rate change implies a protocol sync problem. Are we seeing a problem at the serial connection between your console and the hardware, perhaps? Could you please post a schematic / photos of your configuration? \$\endgroup\$ – Anindo Ghosh Oct 24 '12 at 9:02
  • \$\begingroup\$ Schema is exactly like this: mitchtech.net/wp-content/uploads/2012/08/raspi_arduino_spi.png Except the red goes to 51, red goes to 53, and blue goes to 52. Basically the picture is for an Uno whereas I'm working with an Arduino Mega 2560 \$\endgroup\$ – user1068636 Oct 24 '12 at 12:03
  • \$\begingroup\$ The mismatch is not between the Raspberry Pi and the Arduino, it is between the Arduino and your computer. I'll edit my answer accordingly once you confirm this. Change the serial port data rate at the bottom right of the COMxx window that pops up after clicking Serial Port Monitor in the Arduino software. The baud rate there must match the baud rate you set in your Arduino sketch. \$\endgroup\$ – Anindo Ghosh Oct 24 '12 at 12:12
  • \$\begingroup\$ In my 1st response to you I mentioned I changed the Arudino code to Serial.begin(9600) and re-flashed. When I did that, I also changed the baud rate to 9600 on the Serial Monitor. It still did not work. I increased both sides to different baud rates, but just produced different looking gibrish. My Arduino Mega is connected via USB to my macintosh. Funny thing is when I hard code Serial.println("hello") in the loop() function I can see it in the console correctly. I'm not sure what this means. \$\endgroup\$ – user1068636 Oct 24 '12 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.