Simple Raspberry Pi 4 to Teensy 3.2 Communication

Status
Not open for further replies.

news0und

New member
First off, I'm new to all of this. I tinker a lot. Just trying to get a simple communication script setup with my Raspberry Pi 4 and Teensy 3.2

Right now, I want to run a python script that will set a GPIO pin high or low - Pin is attached to my Teensy 3.2 board. I've attached Pin 12 on the Pi to Pin 2 on the Teensy. Nothing happens when the Python script is running.

Python Script
Code:
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.OUT)

GPIO.output(12, GPIO.HIGH)
print("Pin 12 = HIGH")
time.sleep(5)

GPIO.output(12, GPIO.LOW)
print("Pin 12 = LOW")

time.sleep(5)

GPIO.output(12, GPIO.HIGH)
print("Pin 12 = HIGH")

time.sleep(5)

GPIO.output(12, GPIO.LOW)
print("Pin 12 = LOW")

time.sleep(5)

print("This is the end of the script")

time.sleep(5)

GPIO.cleanup()

Teensy Code

Code:
int ledPin = 13;
int buttonPin = 2;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT);

}

void loop() {
  int buttonState = digitalRead(buttonPin);
  digitalWrite(ledPin, buttonState);

}
 
I'd recommend testing each side separately.

For the Teensy side, try running it stand-alone and just touch a wire from pin 2 to GND or to 3.3V. Does the LED change? You might want to use pinMode INPUT_PULLDOWN rather than INPUT, so it has a default when the pin isn't connected.

For the Raspberry Pi side, also run it stand alone. Connect a voltmeter to pin 12, so you can watch for the changes.

Troubleshooting each side alone is much simpler than trying to figure out what's wrong when they're connected together.
 
use "gpio readall" on the pi I can see the GPIO 12 is being set to OUT mode and the V column switches from 1 to 0 to 1 to 0

Code:
 +-----+-----+---------+------+---+---Pi 4B--+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 |   IN | 1 |  3 || 4  |   |      | 5v      |     |     |
 |   3 |   9 |   SCL.1 |   IN | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 1 | IN   | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 1 | IN   | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |   IN | 0 | 11 ||[COLOR="#B22222"] 12 | 1 | OUT  | GPIO. 1 | 1   | 18  |[/COLOR]

I tried touching the Teensy pin 2 to a 3.3v pin and a ground pin and nothing happened.

The USB of the Teensy is connected to my PC and the only other wire I have connected to it is from the pi to the Teensy on Pin 2 - is this correct?
 
The USB of the Teensy is connected to my PC and the only other wire I have connected to it is from the pi to the Teensy on Pin 2 - is this correct?

In all cases, you need to inter-connect the ground wires between the Teensy and the Pi, so that a circuit can be made.

If you need the two to be electrically separate you can use an opto-coupler. This is a device that internally has one or more LEDs and the same number of light sensors packaged together. On one system, you hook up the ground pin and a data pin to drive the LED. Other the other system you hook up its ground pin and the data pin. With the opo-couplers I've seen in the past, they did not have a resistor for the LEDs, so you would need to figure out the appropriate resistor to use.
 
Good news! I'm dumb!

I had been using Pin 1 instead of Pin 2 - I had looked at the diagram wrong.

Thank you to the both of you for keeping me straight!
 
Status
Not open for further replies.
Back
Top