2

I have set up a Arduino to send a 3.3V signal to my RPi if an object is detected in front of the UltraSonic sensor. I have measured the signal at 3.26V. But it does not work.

Since the signal from the Arduino is 5V and the RPi GPIO pins needs 3.3V, I am using a voltage divider to get 3.3V (measured to 3.26V).

I have tested the program with a button and the Raspberry Pi´s own 3.3V pin, and the state changes are detected, so the program works. I am using Pi4J.

So my question is, why are not the state changed when I use the Arduino to sende the signal?

Here is my code on the RPi (Written in Java):

import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalInput;
import com.pi4j.io.gpio.PinPullResistance;
import com.pi4j.io.gpio.RaspiPin;
import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent;
import com.pi4j.io.gpio.event.GpioPinListenerDigital;

public class ButtonTest{

        public static void main(String[] args) throws InterruptedException{

                final GpioController gpio = GpioFactory.getInstance();

                final GpioPinDigitalInput myButton = gpio.provisionDigitalInputPin(RaspiPin.GPIO_06, "MyButton", PinPullResistance.PULL_DOWN);

                myButton.addListener(new GpioPinListenerDigital(){

                        @Override
                        public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event){

                                System.out.println("GPIO State change: " + event.getPin() + " = " + event.getState());

                        }

                });

                System.out.println("...");

                while(true != false){

                        //Thread.sleep(500);

                }

        }

}

I also have an image of the setup, the only difference is that I take the wire going to the terminal (where I measure) to the GPIO pin #6 on the Raspberry Pi.

enter image description here

Hope someone can give me some answers, thanks!

  • What is gpio pin 6? Do you know the Broadcom gpio number and the pin number on the expansion header? Are you sure that the software is referring to the same pin as the one you have connected? Does the software work if you disconnect the Arduino wire and connect 3V to the pin? Similarly is the alert cancelled if you connect ground to the pin? – joan Oct 4 '14 at 20:25
  • The GPIO_06 refers to the expansion header number 22. And yes, the software is referring to the same pin as I have connected. I have also tested the program with just the 3.3V pin on the RPi and the same GPIO pin and it works, the state changes and the program write the change. “Similarly is the alert cancelled if you connect ground to the pin?” are you referring to the RPi with its own 3.3V pin? – CronbachAlpha Oct 4 '14 at 21:33
  • 1
    If the software works when you replace the Arduino wire with a Pi wire that leaves two possibilities, 1) the Arduino wire high voltage is less than 2.5V, or 2) the Pi's ground is not connected to the Arduino ground. – joan Oct 4 '14 at 22:03
  • It was the Pi's ground... Thank you so much, never thought of that… Again thank you!!!! working now:) – CronbachAlpha Oct 4 '14 at 22:11
  • That is good :-) – joan Oct 4 '14 at 22:34
0

If the software works when you replace the Arduino wire with a Pi wire that leaves two possibilities,

  1. the Arduino wire high voltage is less than 2.5V, or
  2. the Pi's ground is not connected to the Arduino ground.

In this particular case it was the connection of GND of the Pi and the Arduino.


per these comments: 1 and 2

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.