0

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 run multiple times. I have set up the Raspberry Pi and tested it with an LED and the output is working fine.

I then connected this 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 pullup resistors not being used. I would greatly appreciate some guidance on this.

11
  • 2
    setup() runs only once, when the board is switched on (or reset). You should test pin 7 in loop() instead.
    – jfpoilpret
    Commented Dec 22, 2014 at 21:45
  • How do you connect the Arduino with RPi?
    – jfpoilpret
    Commented Dec 22, 2014 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. Commented Dec 22, 2014 at 22:16
  • 3
    Be careful connecting the Raspberry Pi to the arduino directly. The 5V signals on the Arduino can damage the Raspberry Pi.
    – Craig
    Commented Dec 22, 2014 at 22:19
  • 1
    I don't know for sure. But a bug in your arduino code that sets the the input pin as an output would be a problem.
    – Craig
    Commented Dec 22, 2014 at 23:08

3 Answers 3

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.

1
  • 1
    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. Commented Dec 23, 2014 at 15:07
1

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.

3
  • 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. Commented Dec 23, 2014 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. Commented Dec 23, 2014 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. Commented Dec 23, 2014 at 15:20
1

I have done this in a different manner.

I have used the UART TX pin of RPi connected to the RX pin of the arduino and sent serial messages from Arduino to RPi.

That worked fine.

But the thing is, what you have done is correct and has to work.

Please make sure that you have connected Arduino's ground and RPi ground together.


If you not do that and try the same code it has to work. Because the RPi and Arduino are in two different circuits, so in order to work, make them one make GROUND common.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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