Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Novice
1,079 Views

TMP102 I2C Arduino Breakout with mraa

So I'm trying to do my own version of the temperature example using express and the tmp102 breakout.

I have tested the following code with my Arduino due and it works perfectly.

//Arduino 1.0+ Only

//Arduino 1.0+ Only

//////////////////////////////////////////////////////////////////

//©2011 bildr

//Released under the MIT License - Please reuse change and share

//Simple code for the TMP102, simply prints temperature via serial

//////////////////////////////////////////////////////////////////

# include

int tmp102Address = 0x48;

void setup(){

Serial.begin(9600);

Wire.begin();

}

void loop(){

float celsius = getTemperature();

Serial.print("Celsius: ");

Serial.println(celsius);

float fahrenheit = (1.8 * celsius) + 32;

Serial.print("Fahrenheit: ");

Serial.println(fahrenheit);

delay(200); //just here to slow down the output. You can remove this

}

float getTemperature(){

Wire.requestFrom(tmp102Address,2);

byte MSB = Wire.read();

byte LSB = Wire.read();

//it's a 12bit int, using two's compliment for negative

int TemperatureSum = ((MSB << 8) | LSB) >> 4;

float celsius = TemperatureSum*0.0625;

return celsius;

}

I have been reading that only bus 6 can work with the arduino breakout but when I hook up the SDA/SCL Connections and do i2detect -y -r 6 I don't see anything at all which doesn't make any sense. SDA is A4 & SCL is A5 from my understanding and have tried the pins actually labelled SDA/SCL. Section with the '/temp' route is where I'm trying to do my reading.

//

Set this to the ip address of your board (not 127.0.0.1)

var ipAddress = '192.168.2.41';

var mraa = require('mraa'); //require mraa

console.log('MRAA Version: ' + mraa.getVersion()); //write the mraa version to the console

// Load index page into memory to serve when requested

var fs = require('fs');

var index = fs.readFileSync(__dirname + '/index.html','utf8',function(err,data){

if(err)

return console.log(err);

console.log(data);

});

//Initialize the express instance

var express = require('express');

var app = express();

//Serve up our main page if requested

app.get('/',function(req,res)

{

res.set('content-type','text/html');

res.send(index);

res.end();

});

var i2c = new mraa.I2c(6);

i2c.address(0x48);

i2c.frequency(400000);

app.get('/temp',function(req,res) {

console.log("trying to get temperature");

i2c.address(0x48);

var buffer = i2c.read(2);

var msb = i2c.readByte();

var lsb = i2c.readByte();

var temperature = ((msb << 8) | lsb) >> 4;

res.set('content-type','text/plain');

res.send(temperature.toString());

res.end();

});

//Start the server and report that we have started it in the console

var server = app.listen(1337,function(){

var port = server.address().port;

console.log('Example app listening at http://%s:%s',ipAddress,port);

});

4 Replies
Highlighted
Employee
6 Views

Hi ChaseRLewis,

Did you already configure the corresponding GPIO pins of the Arduino Expansion board? If not, this may be the reason of the problem. You can check sections 2.1 to 2.3 of the Arduino Expansion board Hardware Guide for instructions on how to accomplish this.

http://download.intel.com/support/edison/sb/edisonarduino_hg_331191007.pdf http://download.intel.com/support/edison/sb/edisonarduino_hg_331191007.pdf.

Regards,

PabloM_Intel

0 Kudos
Highlighted
Novice
6 Views

So I assume you mean section 11.6? Section 2.1 and 2.3 just tells me which pins to use which I already know. They describe some changes that appears to me to be what I'm supposed to do in Section 11.6 to actually enable the i2c bus on the arduino breakout. I tried using those Linux commands to enable bus 6 in section 11.6 and over half of them give me errors saying 'write error: no such file or directory' or 'write error: no such device'. I have tried copy & pasting and manually doing each command a few times now but none of it seems to matter. It appears from that sheet I have to some how find a way to enable bus 6 to get anything to work, but the commands it is offering to fix the problem do not work. Any ideas?

Tried doing it through the Arduino ide and I just get a constant value of 255°C returned which seems like an error to me. Even when I disconnect the chords I just the same value from the i2c connection.

Sorry this stuff is so ugly tried to format it a bit.

i2c detect from bus 6 after inputting commands

root@tinyEdison:~# i2cdetect -y -r 6

0 1 2 3 4 5 6 7 8 9 a b c d e f

00: -- -- -- -- -- -- -- -- -- -- -- -- --

10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

70: -- -- -- -- -- -- -- --

root@tinyEdison:~#

root@tinyEdison:~# ^C

Console output from commands

root@tinyEdison:~# echo 28 > /sys/class/gpio/export

root@tinyEdison:~# echo 27 > /sys/class/gpio/export

root@tinyEdison:~# echo 204 > /sys/class/gpio/export ...

0 Kudos
Highlighted
Employee
6 Views

Hi ChaseRLewis,

I apologize for the late reply. I just run the same commands that you entered in your second image and I'm not getting any error message, you can see the image below.

 

Which image are you using (you can enter configure_edison –version to get this information)? Which Edison platform do you have, Arduino Expansion Board or the Mini-breakout Board?

I would also suggest you to check this thread /thread/55839 https://communities.intel.com/thread/55839. Some other users have reported this behavior when using the multiplexing guide, maybe you can find some solutions.

Regards,

PabloM_Intel

0 Kudos
Highlighted
Employee
6 Views

Hi ChaseRLewis,

Have you been able to use the TMP102 successfully with your board?

Regards,

Charlie

0 Kudos