Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: Simple Raspberry Pi 4 to Teensy 3.2 Communication

  1. #1
    Junior Member
    Join Date
    Jun 2020
    Posts
    3

    Simple Raspberry Pi 4 to Teensy 3.2 Communication

    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);
    
    }

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,513
    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.

  3. #3
    Junior Member
    Join Date
    Jun 2020
    Posts
    3
    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 || 12 | 1 | OUT  | GPIO. 1 | 1   | 18  |
    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?

  4. #4
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,837
    Quote Originally Posted by news0und View Post
    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.

  5. #5
    Junior Member
    Join Date
    Jun 2020
    Posts
    3
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •