Claudius310
Member
hello,
I am from France and I do not speak English very well (excuse me)
problem 1)
I bought a teensy 3.6 but could not use the I2C bus
I tried doing the i2c Arduino test and i have no answer in the IDE monitor
see code:
#include <i2c_t3.h>
// --------------------------------------
// i2c_scanner
//
// Version 1
// This program (or code that looks like it)
// can be found in many places.
// For example on the Arduino.cc forum.
// The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
// Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26 2013
// V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
// by Arduino.cc user Krodal.
// Changes by louarnold removed.
// Scanning addresses changed from 0...127 to 1...119,
// according to the i2c scanner by Nick Gammon
// http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
// As version 4, but address scans now to 127.
// A sensor seems to use address 120.
// Version 6, November 27, 2015.
// Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//
void setup()
{
Wire1.begin();
Serial.begin(9600);
while (!Serial); // Leonardo: wait for serial monitor
Serial.println("\nI2C Scanner");
}
void loop()
{
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknow error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(5000); // wait 5 seconds for next scan
}
I tried with Wire and Wire1 with pins 19,18 or 37; 38 it's the same
The sensor works with an Arduino
I tried with the tennsy example program
see code of the basic scanner
I2C Bus Scanner
// -------------------------------------------------------------------------------------------
//
// This creates an I2C master device which will scan the address space and report all
// devices which ACK. It does not attempt to transfer data, it only reports which devices
// ACK their address.
//
// Pull the control pin low to initiate the scan. Result will output to Serial.
//
// This example code is in the public domain.
// -------------------------------------------------------------------------------------------
#include <i2c_t3.h>
// Function prototypes
void print_scan_status(uint8_t target, uint8_t all);
uint8_t found, target, all;
void setup()
{
pinMode(LED_BUILTIN,OUTPUT); // LED
pinMode(12,INPUT_PULLUP); // pull pin 12 low to show ACK only results
pinMode(11,INPUT_PULLUP); // pull pin 11 low for a more verbose result (shows both ACK and NACK)
// Setup for Master mode, pins 18/19, external pullups, 400kHz, 10ms default timeout
Wire.begin(I2C_MASTER, 0x00, I2C_PINS_18_19, I2C_PULLUP_EXT, 400000);
Wire.setDefaultTimeout(10000); // 10ms
Serial.begin(115200);
}
void loop()
{
// Scan I2C addresses
//
if(digitalRead(12) == LOW || digitalRead(11) == LOW)
{
all = (digitalRead(11) == LOW);
found = 0;
Serial.print("---------------------------------------------------\n");
Serial.print("Starting scan...\n");
digitalWrite(LED_BUILTIN,HIGH); // LED on
for(target = 1; target <= 0x7F; target++) // sweep addr, skip general call
{
Wire.beginTransmission(target); // slave addr
Wire.endTransmission(); // no data, just addr
print_scan_status(target, all);
}
digitalWrite(LED_BUILTIN,LOW); // LED off
if(!found) Serial.print("No devices found.\n");
delay(100); // delay to space out tests
}
}
//
// print scan status
//
void print_scan_status(uint8_t target, uint8_t all)
{
switch(Wire.status())
{
case I2C_WAITING:
Serial.printf("Addr: 0x%02X ACK\n", target);
found = 1;
break;
case I2C_ADDR_NAK:
if(all) Serial.printf("Addr: 0x%02X\n", target);
break;
default:
break;
}
}
The result is the same, no display in the monitor, the program is blocked?
Problem 2)
I tried to compile the Sparkfun program for the MPL3115A2 sensor
See code:
#include <i2c_t3.h>
#include "SparkFunMPL3115A2.h"
//Create an instance of the object
MPL3115A2 myPressure;
void setup()
{
Serial.begin(9600); // Start serial for output
Wire1.begin(); // Join i2c bus
myPressure.begin(); // Get sensor online
//Configure the sensor
myPressure.setModeAltimeter(); // Measure altitude above sea level in meters
//myPressure.setModeBarometer(); // Measure pressure in Pascals from 20 to 110 kPa
myPressure.setOversampleRate(7); // Set Oversample to the recommended 128
myPressure.enableEventFlags(); // Enable all three pressure and temp event flags
}
void loop()
{
float altitude = myPressure.readAltitude();
Serial.print("Altitude(m):");
Serial.print(altitude, 2);
//float altitude = myPressure.readAltitudeFt();
//Serial.print(" Altitude(ft):");
//Serial.print(altitude, 2);
float pressure = myPressure.readPressure();
Serial.print("Pressure(Pa):");
Serial.print(pressure, 2);
//float temperature = myPressure.readTemp();
//Serial.print(" Temp(c):");
//Serial.print(temperature, 2);
float temperature = myPressure.readTempF();
Serial.print(" Temp(f):");
Serial.print(temperature, 2);
Serial.println();
}
But I have the following error
Arduino : 1.8.1 (Windows 10), TD: 1.35, Carte : "Teensy 3.6, Serial, 180 MHz, Fast, US English"
In file included from C:\Users\jcc\Documents\Arduino\libraries\SparkFun_MPL3115A2_Altitude_and_Pressure_Sensor_Breakout\src/SparkFunMPL3115A2.h:19:0,
from C:\Users\jcc\AppData\Local\Temp\arduino_modified_sketch_41314\SparkFunAltimeter.ino:36:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Wire/Wire.h:104:16: error: conflicting declaration 'TwoWire Wire'
extern TwoWire Wire;
^
In file included from C:\Users\jcc\AppData\Local\Temp\arduino_modified_sketch_41314\SparkFunAltimeter.ino:35:0:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\i2c_t3/i2c_t3.h:987:15: error: 'Wire' has a previous declaration as 'i2c_t3 Wire'
extern i2c_t3 Wire;
^
Erreur de compilation pour la carte Teensy 3.6
Ce rapport pourrait être plus détaillé avec
l'option "Afficher les résultats détaillés de la compilation"
activée dans Fichier -> Préférences.
Thank you for your help
Regards
jean-claude
I am from France and I do not speak English very well (excuse me)
problem 1)
I bought a teensy 3.6 but could not use the I2C bus
I tried doing the i2c Arduino test and i have no answer in the IDE monitor
see code:
#include <i2c_t3.h>
// --------------------------------------
// i2c_scanner
//
// Version 1
// This program (or code that looks like it)
// can be found in many places.
// For example on the Arduino.cc forum.
// The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
// Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26 2013
// V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
// by Arduino.cc user Krodal.
// Changes by louarnold removed.
// Scanning addresses changed from 0...127 to 1...119,
// according to the i2c scanner by Nick Gammon
// http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
// As version 4, but address scans now to 127.
// A sensor seems to use address 120.
// Version 6, November 27, 2015.
// Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//
void setup()
{
Wire1.begin();
Serial.begin(9600);
while (!Serial); // Leonardo: wait for serial monitor
Serial.println("\nI2C Scanner");
}
void loop()
{
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknow error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(5000); // wait 5 seconds for next scan
}
I tried with Wire and Wire1 with pins 19,18 or 37; 38 it's the same
The sensor works with an Arduino
I tried with the tennsy example program
see code of the basic scanner
I2C Bus Scanner
// -------------------------------------------------------------------------------------------
//
// This creates an I2C master device which will scan the address space and report all
// devices which ACK. It does not attempt to transfer data, it only reports which devices
// ACK their address.
//
// Pull the control pin low to initiate the scan. Result will output to Serial.
//
// This example code is in the public domain.
// -------------------------------------------------------------------------------------------
#include <i2c_t3.h>
// Function prototypes
void print_scan_status(uint8_t target, uint8_t all);
uint8_t found, target, all;
void setup()
{
pinMode(LED_BUILTIN,OUTPUT); // LED
pinMode(12,INPUT_PULLUP); // pull pin 12 low to show ACK only results
pinMode(11,INPUT_PULLUP); // pull pin 11 low for a more verbose result (shows both ACK and NACK)
// Setup for Master mode, pins 18/19, external pullups, 400kHz, 10ms default timeout
Wire.begin(I2C_MASTER, 0x00, I2C_PINS_18_19, I2C_PULLUP_EXT, 400000);
Wire.setDefaultTimeout(10000); // 10ms
Serial.begin(115200);
}
void loop()
{
// Scan I2C addresses
//
if(digitalRead(12) == LOW || digitalRead(11) == LOW)
{
all = (digitalRead(11) == LOW);
found = 0;
Serial.print("---------------------------------------------------\n");
Serial.print("Starting scan...\n");
digitalWrite(LED_BUILTIN,HIGH); // LED on
for(target = 1; target <= 0x7F; target++) // sweep addr, skip general call
{
Wire.beginTransmission(target); // slave addr
Wire.endTransmission(); // no data, just addr
print_scan_status(target, all);
}
digitalWrite(LED_BUILTIN,LOW); // LED off
if(!found) Serial.print("No devices found.\n");
delay(100); // delay to space out tests
}
}
//
// print scan status
//
void print_scan_status(uint8_t target, uint8_t all)
{
switch(Wire.status())
{
case I2C_WAITING:
Serial.printf("Addr: 0x%02X ACK\n", target);
found = 1;
break;
case I2C_ADDR_NAK:
if(all) Serial.printf("Addr: 0x%02X\n", target);
break;
default:
break;
}
}
The result is the same, no display in the monitor, the program is blocked?
Problem 2)
I tried to compile the Sparkfun program for the MPL3115A2 sensor
See code:
#include <i2c_t3.h>
#include "SparkFunMPL3115A2.h"
//Create an instance of the object
MPL3115A2 myPressure;
void setup()
{
Serial.begin(9600); // Start serial for output
Wire1.begin(); // Join i2c bus
myPressure.begin(); // Get sensor online
//Configure the sensor
myPressure.setModeAltimeter(); // Measure altitude above sea level in meters
//myPressure.setModeBarometer(); // Measure pressure in Pascals from 20 to 110 kPa
myPressure.setOversampleRate(7); // Set Oversample to the recommended 128
myPressure.enableEventFlags(); // Enable all three pressure and temp event flags
}
void loop()
{
float altitude = myPressure.readAltitude();
Serial.print("Altitude(m):");
Serial.print(altitude, 2);
//float altitude = myPressure.readAltitudeFt();
//Serial.print(" Altitude(ft):");
//Serial.print(altitude, 2);
float pressure = myPressure.readPressure();
Serial.print("Pressure(Pa):");
Serial.print(pressure, 2);
//float temperature = myPressure.readTemp();
//Serial.print(" Temp(c):");
//Serial.print(temperature, 2);
float temperature = myPressure.readTempF();
Serial.print(" Temp(f):");
Serial.print(temperature, 2);
Serial.println();
}
But I have the following error
Arduino : 1.8.1 (Windows 10), TD: 1.35, Carte : "Teensy 3.6, Serial, 180 MHz, Fast, US English"
In file included from C:\Users\jcc\Documents\Arduino\libraries\SparkFun_MPL3115A2_Altitude_and_Pressure_Sensor_Breakout\src/SparkFunMPL3115A2.h:19:0,
from C:\Users\jcc\AppData\Local\Temp\arduino_modified_sketch_41314\SparkFunAltimeter.ino:36:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Wire/Wire.h:104:16: error: conflicting declaration 'TwoWire Wire'
extern TwoWire Wire;
^
In file included from C:\Users\jcc\AppData\Local\Temp\arduino_modified_sketch_41314\SparkFunAltimeter.ino:35:0:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\i2c_t3/i2c_t3.h:987:15: error: 'Wire' has a previous declaration as 'i2c_t3 Wire'
extern i2c_t3 Wire;
^
Erreur de compilation pour la carte Teensy 3.6
Ce rapport pourrait être plus détaillé avec
l'option "Afficher les résultats détaillés de la compilation"
activée dans Fichier -> Préférences.
Thank you for your help
Regards
jean-claude