How to read digital pins of Robo Hat of Picar V?

I’m a teacher,my school bought the car a few months ago, and we want to read and write to the digital pins of the Robo Hats. In your webpage and GitHub there is nothing about it. Could you send us and example of how to read from the digital pins of the Robo Hat? In Python if possible.

I attach some pictures of the car to see the model and the pins I would like to know how to read/write to teach my students.

We need to connect a button and an ultrasonic sensor.


The digital pins on the robot-hat board of PiCar-V are directly connected to the corresponding pins of the Raspberry Pi.
To read the ultrasonic module’s data, you can refer to the tutorial in our Sensor Kit, and you need to pay attention to the corresponding pins.
Change the pins in the code: Lesson 25 Ultrasonic Ranging Module — SunFounder SunFounder_SensorKit_for_RPi2 documentation

We have connected the ultrasound sensor HC-SR04 as seen in the tutorial changing to our pins, but it not works well. Sometimes it gives correct values, but other time gives values like -0.1 and it freezes. We have tested several sensors and cables.

I have read on Internet that this sensor works better at 5v instead 3.3v that supplies the Robo Hat of the Picar. Is it possible? Don’t need any resistor?

The problem you mentioned did not appear when we tested it.

It may be the quality problem of the DuPont line.

It should be noted that the pins on Robot_Hats are numbers using BCM, and the code should pay attention to the use:

def setup():

#GPIO.setmode(GPIO.BOARD)

GPIO.setmode(GPIO.BCM)

GPIO.setup(ECHO, GPIO.IN)

GPIO.setup(TRIG, GPIO.OUT)

GPIO.setup(ECHO, GPIO.IN)

Yes, we did with BCM mode and the code as shown, but we only achieve to run properly connecting to 5v with resistors.

May be the ultrasonic module you used is different from the one we tested, which works fine with 3.3V.

Catch(09-19-14-0(12-14-15-24-55)

The red VIN voltage on the PCA9685 board is 5V, you can use this interface to power the ultrasonic

Yes, we are using the 5v pins and it runs perfect.

Thanks for your help! :laughing:

You’re welcome. Glad to help. :sunglasses: