Sign up ×
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It's 100% free, no registration required.

I am trying to control an Arduino Leonardo R3 to run some code when "triggered" from a Raspberry Pi, this would be in a loop so that it can be ran multiple times. I have setup the Raspberry Pi and tested it with an LED and the output is working fine.

I then connected this up to the Arduino and checked for a HIGH input from the RPi using an if statement.

void setup()
{
  pinMode(7,INPUT);


  if(digitalRead(7)==HIGH)
  {
  CODE IN HERE
  }
}

I found that this did not work as the if statement was always true because of pull up resistors not being used. I would greatly appreciate some guidance on this.

share|improve this question
1  
setup() runs only once, when the board is switched on (or reset). You should test pin 7 in loop() instead. –  jfpoilpret Dec 22 '14 at 21:45
    
How do you connect the Arduino with RPi? –  jfpoilpret Dec 22 '14 at 21:46
    
The reason I put it in setup first was because if I did something wrong didnt want it to continue constantly. I connected the GPIO from the RPi direct to the Arduino pin 7. –  Rahul Khosla Dec 22 '14 at 22:16
2  
Be careful connecting the Raspberry Pi to the arduino directly. The 5V signals on the Arduino can damage the Raspberry Pi. –  Craig Dec 22 '14 at 22:19
    
The Arduino is being used as an input, will this be OK? –  Rahul Khosla Dec 22 '14 at 22:31

2 Answers 2

You have to verify, at least:

A. if the 3.3V of the RPi can be read as high on the Atmega, if so you can connect them without any resistor.

B. if not, you have to use a voltage adapter (yes, other components and many possible solutions), otherwise you RPi GPIO will be ruined if using a pullup on the 5V.

The pullup and pulldown, in this case, should be used when you are in A and the peripheral support the higher voltage. This is not the case.

share|improve this answer
    
No adapter or pullup is needed - an ATmega at 5v actually has a lower threshold for a "1" than the pi's 3.3v CPU does. –  Chris Stratton Dec 23 '14 at 15:07

I don't have much experience about Arduino boards connected to the Pi, never tried anything other than Arduino Due, but I do have some experiences with ATmega328P directly attached to the Pi. The ATmega is clocked at 12MHz instead of 16 to guarantee a stable state at 3.3V supply voltage.

Physical connection takes 5 signal wires besides the 3.3V power rail, with the ATmega talking with the Pi over SPI as a slave device, using both slave select lines, one at the SS pin and the other at RESET pin. This allows communication over proper hardware interfaces while eliminates the need of a programmer or preprogrammed chips as the ATmega use its SPI interface as ICSP, this setup essentially keep ICSP properly wired to the Pi at all times. An additional pin can be used as a IRQ pin from the ATmega to the Pi.

About the protocol that part is up to yourself. There are endless possibilities and you can implement anything that fits your need and easy to use.

share|improve this answer
    
That's possible, yes, but seems a lot more than what the poster is trying to achieve. USB current limits on various pi models aside, one can also plug the Arduino into the pi's USB instead of a PC's. –  Chris Stratton Dec 23 '14 at 15:10
    
I have built myself a Arduino-like shield for Pi based on this idea. And it uses fresh chips, no bootloader required. –  Maxthon Chan Dec 23 '14 at 15:14
    
That's nice, but a lot more work and not really what the poster seems to be trying to do at this point. –  Chris Stratton Dec 23 '14 at 15:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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