Teensy 3.2 and Adafruit Circuit Playground Express: I2C vs Serial?

Status
Not open for further replies.

sumnerdr

Member
Hi All,

I have a feasibility question regarding communication between Teensy 3.2 and an Adafruit Circuit Playground Express.

I would like to make a portable synth that uses the Circuit Playground as a "sensor board" of sorts for 3.2 and the Audio Library.
I'm working on using the onboard sensors (light, accelerometer, etc) on the CPX as realtime inputs to a synth running on Teensy 3.2.

Is there any logic as to if it would be smarter to use I2C or to use SPI for this kind of project?
(also of note...it will be battery powered...)
Will I need to use pullup resistors between these boards for I2C?

Is there any guidance / resources on the code and hardware connections I would need to make for this project?

Thank you!

DS
 
Last edited:
Would the choice of using I2C vs. SPI for communication between the CPX and Teensy have any effect on how the Teensy Audio Library runs?
Thanks~
 
I2C and SPI should work fine with Audio library. First trial for me would be to use UART Serial just crossing RX and TX and connecting GND would allow transferring custom messages as needed. The T_3.2 can probably run at higher baud rates than the M0 on the CPX - but with Serial1 and 2 on T_3.2 having a hardware FIFO the messages on the Teensy side should work to receive and be ready.

Yes, for i2c there have to be pullups on those lines somewhere.
 
Awesome, thank you!
I shouldn't need the pullups for the Uart serial...right?
Just straight connections between the RX, TX, and GND...

Cheers~
 
Awesome, thank you!
I shouldn't need the pullups for the Uart serial...right?
Just straight connections between the RX, TX, and GND...

Cheers~

Correct - using the UART Serial is just a direct wired crossed connection RX<>TX both ways - and common GND. Then a common baud rate - the Teensy should handle the fastest the CPX can reliably use.
 
Spent the weekend working on this, without any luck!
At this point: just trying to establish serial between Teensy and Circuit playground.
GNDS connected together, Teensy RX (Pin 0) to CPX TX, and Teensy TX (Pin 1) to CPX RX.

Code on the Teensy:
Code:
#define HWSERIAL Serial1

int led = 13;

void setup() {
  Serial.begin(9600);
  HWSERIAL.begin(9600);
  pinMode(led, OUTPUT);
}

void blink() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(100);               // wait for a second
  digitalWrite(led, LOW);
}

void loop() {

  int incomingByte;
        
  if (Serial.available() > 0) {
    incomingByte = Serial.read();
    Serial.print("USB received: ");
    Serial.println(incomingByte, DEC);
    HWSERIAL.print("USB received:");
    HWSERIAL.println(incomingByte, DEC);
    blink();
  }

  if (HWSERIAL.available() > 0) {
    incomingByte = HWSERIAL.read();
    Serial.print("UART received: ");
    Serial.println(incomingByte, DEC);
    HWSERIAL.print("UART received:");
    HWSERIAL.println(incomingByte, DEC);
    blink();
  }
}

and, code on the Circuit Playground:
Code:
int led = 13;

void setup() {
  // put your setup code here, to run once:
  pinMode(led, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.write(0xff);
  delay(2000);
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(100);               // wait for a second
  digitalWrite(led, LOW); 
}

....
Any advice on what I am doing wrong here would be greatly appreciated. Thanks!
 
Last edited:
You say - 'what am I doing wrong' … giving a note about what is seen as wrong would help to know the expected behavior.

Having blink() used prominently - and having delay(100) in that is not a good idea. Usually just knowing the current value - or the last written - and toggle that and write - so it will just change state on each new character.

I use this and just call qBlink(); :: #define qBlink() (digitalWriteFast(LED_BUILTIN, !digitalReadFast(LED_BUILTIN) ))

it might help to have CPX code looking for input and pulling it from the buffer and maybe blink differently?
 
Hey defragster,

Thanks for the quick reply!

My apologies -- I totally failed to include a description of the issue in previous post.
I was expecting the Teensy LED to blink when CPX sends over serial -- as a simple way of testing the connection -- though never was able to get that result.

Going to edit my code per your suggestions and keep at it.

Thanks again for the help!

DS
 
That's strange indeed.
Just to better isolate the problem, what about simplifying your Teensy code, like

Code:
#define HWSERIAL Serial1

void setup() 
{
  Serial.begin(9600);
  HWSERIAL.begin(9600);
}

void loop() 
{
  byte incomingByte;
        
  if (HWSERIAL.available()) 
 {
    incomingByte = HWSERIAL.read();
    Serial.print("UART received: ");
    Serial.println(incomingByte, DEC);
  }
}

and adding a Serial.flush() to the Circuit Playground sketch?
 
Still struggling to find what I am doing wrong here!
Haven't been able to establish even the most basic of serial connections between CPX and Teensy...

I have the code XFer posted above on the Teensy, and this code on CPX:
Code:
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.write(0xff); 
    delay(1000);
}

I have also tried adding Serial.flush() to the CPX code, and omitting the Blink sections altogether...I'm still not able to see anything printing/being transmitted when monitoring Teensy via Serial on my computer. Are there any other glaring things I am missing? It seems both Teensy and CPX are TTL serial, so that *shouldn't* be the issue here.

When connected to USB serial, I can see that the CPX is transmitting in my computer's serial monitor.
(Of course, am unplugging CPX from USB power, and powering it with a battery for the CPX to Teensy Serial communication I'm hoping to achieve).

.thanks again for all of the assistance...it is super appreciated.

EDIT: When monitoring Serial via USB on the Teensy, and reconnecting the TX and RX cables to CPX, occasionally a few random things get spit out in the Serial Monitor (Teensy is receiving them on Serial1)...makes it seem like it could be a hardware/software issue on the CPX end?

DS
 
Last edited:
Problem has been solved! Turns out, the CPX needs to use Serial1 instead of Serial for hardware UART...thanks again for the help here.
 
Status
Not open for further replies.
Back
Top