Smart Car pins
This page lists the pins of the Smart Car board. The numbers come from the board’s definition in the firmware. They are GPIO numbers: the numbers the ESP32 chip gives its pins, and the numbers the firmware passes to machine.Pin.
You do not need them to drive the robot. Use robot.left_motor, robot.led1 and the other parts from the Smart Car page. You need the numbers when you wire something of your own, or when you read the firmware.
This page is for the standard Smart Car, which has a DRV8833 motor driver and a battery sensor. The first Smart Cars have an L298N and no battery sensor, and their motor pins are at the end of this page.
Motors
Section titled “Motors”The DRV8833 has two inputs for each motor and no separate enable pin. The firmware sends PWM to the inputs.
| Part | Signal | GPIO |
|---|---|---|
| Left motor | Input 1 | 18 |
| Left motor | Input 2 | 19 |
| Right motor | Input 1 | 16 |
| Right motor | Input 2 | 17 |
The firmware uses a PWM frequency of 1000 Hz for the motors.
Lights, buzzer and button
Section titled “Lights, buzzer and button”| Part | In code | GPIO |
|---|---|---|
| LED 1 | robot.led1 |
15 |
| LED 2 | robot.led2 |
2 |
| Buzzer | robot.buzzer |
23 |
| Button | none in firmware 3.0 | 13 |
The board’s definition lists GPIO 13 as the button. Firmware 3.0 does not use it: Bluetooth is always on, so there is no robot.button.
Sensors
Section titled “Sensors”Line sensor
Section titled “Line sensor”Five infrared eyes. The list starts at the leftmost eye, and robot.line_sensor.read() gives the values in the same order.
| Part | In code | GPIO |
|---|---|---|
| Line sensor, eye 1 (leftmost) | robot.line_sensor.read(0) |
36 |
| Line sensor, eye 2 | robot.line_sensor.read(1) |
39 |
| Line sensor, eye 3 | robot.line_sensor.read(2) |
34 |
| Line sensor, eye 4 | robot.line_sensor.read(3) |
35 |
| Line sensor, eye 5 (rightmost) | robot.line_sensor.read(4) |
32 |
Distance sensor
Section titled “Distance sensor”An ultrasonic sensor. The echo timeout is 30000 microseconds (30 milliseconds). If no echo comes back in that time, the driver does not report an error. It uses a fixed time of 11640 microseconds, which is how long sound needs to travel 400 centimetres, there and back. The distance is half of that, so distance_cm() gives 200.0 and distance_mm() gives 2000. A clear space in front of the sensor therefore reads 200 centimetres, not -1. A -1 is rare: it only comes if the driver reports an error.
| Part | Signal | GPIO |
|---|---|---|
| Distance sensor | Trigger | 14 |
| Distance sensor | Echo | 27 |
Battery sensor
Section titled “Battery sensor”| Part | Signal | GPIO |
|---|---|---|
| Battery sensor | Analog input | 33 |
The battery voltage is divided down before it reaches the pin: 20000 ohms on the top side and 10000 ohms on the bottom side, and the chip’s reference is 3.3 volts. The pin sees one third of the battery voltage, so robot.battery.voltage() multiplies by three.
I2C bus
Section titled “I2C bus”The colour sensor and the compass share one I2C bus (bus number 0).
| Bus signal | GPIO |
|---|---|
| SCL (clock) | 22 |
| SDA (data) | 21 |
| Device | I2C address |
|---|---|
| Colour sensor (TCS34725) | 0x29 |
| Compass, chip 1 of 3: HMC5883L | 0x1E |
| Compass, chip 2 of 3: QMC5883L | 0x0D |
| Compass, chip 3 of 3: QMC5883P | 0x2C |
The compass is one of three chips. The firmware finds out which one is fitted when it starts, by asking at each address in the order above.
Servos and joysticks
Section titled “Servos and joysticks”These are add-ons. They are off until you call robot.enable_servos() or robot.enable_joysticks(). The servos use a PWM frequency of 50 Hz.
| Part | In code | GPIO |
|---|---|---|
| Servo 1 | robot.servo1 |
32 |
| Servo 2 | robot.servo2 |
33 |
| Servo 3 | robot.servo3 |
25 |
| Servo 4 | robot.servo4 |
26 |
| Part | Axis | GPIO |
|---|---|---|
| Joystick 1 | x (left and right) | 39 |
| Joystick 1 | y (forward and back) | 36 |
| Joystick 2 | x (left and right) | 35 |
| Joystick 2 | y (forward and back) | 34 |
Shared pins
Section titled “Shared pins”A few pins belong to two parts. This is on purpose: the chip does not have enough pins for every add-on, so parts that are alternatives share a pin, and you choose which one you are using. The board’s definition says a Smart Car is wired for the line sensor or for servos and joysticks, never both at once.
| GPIO | Used by | Also used by |
|---|---|---|
| 32 | Line sensor, eye 5 | Servo 1 |
| 33 | Battery sensor | Servo 2 |
| 34 | Line sensor, eye 3 | Joystick 2 |
| 35 | Line sensor, eye 4 | Joystick 2 |
| 36 | Line sensor, eye 1 | Joystick 1 |
| 39 | Line sensor, eye 2 | Joystick 1 |
Servo 2 uses GPIO 33, the pin the battery sensor reads. Use one or the other.
PWM and timers
Section titled “PWM and timers”| Part | PWM frequency |
|---|---|
| Motors | 1000 Hz |
| LED 1 and LED 2 | 5000 Hz |
| Buzzer | changes with every note |
| Servos | 50 Hz |
Timer 0 plays the buzzer’s notes. The board’s definition also sets timer 1 aside for the motor failsafe, a safety stop for the motors.
The early L298N board
Section titled “The early L298N board”The first Smart Cars use an L298N motor driver instead of the DRV8833. It has one PWM enable pin and two direction pins for each motor. All the other pins on this page are the same on that board, except that it has no battery sensor, so GPIO 33 is only servo 2.
| Part | Signal | GPIO |
|---|---|---|
| Left motor | Enable (PWM, sets the speed) | 5 |
| Left motor | Direction input 1 | 18 |
| Left motor | Direction input 2 | 19 |
| Right motor | Enable (PWM, sets the speed) | 4 |
| Right motor | Direction input 1 | 16 |
| Right motor | Direction input 2 | 17 |
The L298N motors use a PWM frequency of 100 Hz. This chassis does not turn below about half power, so the firmware spreads speeds 1 to 100 over 50 to 100 percent of full power.
The firmware has a separate image for this board. It is called smart-car-l298n.