https://www.adafruit.com/product/3965
So I went and bought a pressure sensor board from Adafruit thinking that it would run fine on the Teensy 3.6 over I2C. So far, I am so wrong...
Adafruit has their own dead simple library which base off of the Wire.h library but I know that's not going to be compatible with the Teensy. So I went to the i2c_t3 library to see if I could get that to work, and so far I am not able to communicate with the board at all, let alone get any data.
I am using Pin 3 for SCL, Pin 4 for SDA on the Teensy 3.6.
I tried all manner of these examples libraries but I can't get any of them to work on this board.
Here's the code I have.
I am assuming that in this configuration, I am wanting a master to slave (MPRLS) configuration. The board is said to only listen on 0x18 address and, hopefully, that doesn't conflict with anything else I need on the Teensy (how could I figure that out?). I am using external 10k pullup resistors on both the SCL and SDA pins.
Can anyone help with this?
If I can't get this to work, I'm going to need to abandon the Teensy for this project.
Thanks
So I went and bought a pressure sensor board from Adafruit thinking that it would run fine on the Teensy 3.6 over I2C. So far, I am so wrong...
Adafruit has their own dead simple library which base off of the Wire.h library but I know that's not going to be compatible with the Teensy. So I went to the i2c_t3 library to see if I could get that to work, and so far I am not able to communicate with the board at all, let alone get any data.
I am using Pin 3 for SCL, Pin 4 for SDA on the Teensy 3.6.
I tried all manner of these examples libraries but I can't get any of them to work on this board.
Here's the code I have.
Code:
// -------------------------------------------------------------------------------------------
// Basic Master
// -------------------------------------------------------------------------------------------
//
// This creates a simple I2C Master device which when triggered will send/receive a text
// string to/from a Slave device. It is intended to pair with a Slave device running the
// basic_slave sketch.
//
// Pull pin12 input low to send.
// Pull pin11 input low to receive.
//
// This example code is in the public domain.
//
// -------------------------------------------------------------------------------------------
#include <i2c_t3.h>
// Memory
#define MEM_LEN 256
char databuf[MEM_LEN];
int count;
void setup()
{
pinMode(LED_BUILTIN,OUTPUT); // LED
digitalWrite(LED_BUILTIN,LOW); // LED off
pinMode(3,INPUT_PULLUP); // Control for Send
pinMode(4,INPUT_PULLUP); // Control for Receive
// Setup for Master mode, pins 18/19, external pullups, 400kHz, 200ms default timeout
Wire.begin(I2C_MASTER, 0x00, I2C_PINS_3_4, I2C_PULLUP_EXT, 400000);
Wire.setDefaultTimeout(200000); // 200ms
// Data init
memset(databuf, 0, sizeof(databuf));
count = 0;
Serial.begin(9600);
}
void loop()
{
uint8_t target = 0x18; // target Slave address
// Send string to Slave
//
if(digitalRead(12) == LOW)
{
digitalWrite(LED_BUILTIN,HIGH); // LED on
// Construct data message
sprintf(databuf, "Data Message #%d", count++);
// Print message
Serial.printf("Sending to Slave: '%s' ", databuf);
// Transmit to Slave
Wire.beginTransmission(target); // Slave address
Wire.write(databuf,strlen(databuf)+1); // Write string to I2C Tx buffer (incl. string null at end)
Wire.endTransmission(); // Transmit to Slave
// Check if error occured
if(Wire.getError())
Serial.print("FAIL\n");
else
Serial.print("OK\n");
digitalWrite(LED_BUILTIN,LOW); // LED off
delay(100); // Delay to space out tests
}
// Read string from Slave
//
if(digitalRead(11) == LOW)
{
digitalWrite(LED_BUILTIN,HIGH); // LED on
// Print message
Serial.print("Reading from Slave: ");
// Read from Slave
Wire.requestFrom(target, (size_t)MEM_LEN); // Read from Slave (string len unknown, request full buffer)
// Check if error occured
if(Wire.getError())
Serial.print("FAIL\n");
else
{
// If no error then read Rx data into buffer and print
Wire.read(databuf, Wire.available());
Serial.printf("'%s' OK\n",databuf);
}
digitalWrite(LED_BUILTIN,LOW); // LED off
delay(100); // Delay to space out tests
}
}
I am assuming that in this configuration, I am wanting a master to slave (MPRLS) configuration. The board is said to only listen on 0x18 address and, hopefully, that doesn't conflict with anything else I need on the Teensy (how could I figure that out?). I am using external 10k pullup resistors on both the SCL and SDA pins.
Can anyone help with this?
If I can't get this to work, I'm going to need to abandon the Teensy for this project.
Thanks