How to process output of a i2c sensor to get proper values. #3027
Replies: 15 comments
-
|
Posted at 2019-07-26 by Robin Fri 2019.07.26 Hello @user101989,
It appears you understand your situation accurately!! wink, wink But seriously now, would you please post the output, that is generated from the code segment above, from the left-hand side of the WebIDE so that we may get an idea of what 'i am getting a senseless value' actually means to us. So far nothing stands out. Code segment appears okay. Puck flashed to latest firmware? What ver please.
Is there a common ground between the two devices? How was the sensor grounded on your Arduino setup? If the sensor is floating, might explain the erroneous values. Any chance you could post an image of the wiring and the schematic link to see if there is a I2C setup or wiring issue? e.g. sda scl backwards -
Do you have access to a logic analyzer and protocol decoder? I highly recommend (eventually~$20USD) getting one. Has saved me multiple times. See this image I recently posted. |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2019-07-26 by user101989 Thanks for your input I will next time do all this checklist you suggest because it all makes sense to try, specially the analyzer and decoder thing. !!! I figured it out by bruteforcing trial and error attempts. In the end I had to change the 1 in line 8 for a 0. Doing that did the trick. I have no clue why! |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2019-07-26 by Robin
No clue without the sensor command set, which wasn't in #1 Maybe argument 2 in L8 should be Sometimes brute force does work. ;-) Glad you got it working! |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2019-07-26 by maze1980 Just a code snipped: I didn't try/check your code in detail, but I'd suggest to define data (or b) as Uint8Array. |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2019-07-26 by AkosLukacs Assuming that's a TI TMP117 (providing a link to the chip and / or the library you try to port sometimes helps, or saves a couple of seconds), the Arduino code simply reads two bytes from register At line 17 that delay I don't think its necessary for two reasons:
I think @maze1980 is pretty close, this probably works: |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2019-07-26 by AkosLukacs Looks like I2C.readFrom already returns an Uint8Array, so I think you are doing a double allocation. Or not, or might not even be measurable, if that allocation is just in a small function, and the GC frees up memory... |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2019-07-26 by user101989 As I said in my previous post. I managed to fix it by changing line 8 in which I write 1 to instead write 0, this seems to clear the previous measurement or something in the TMP117 and then the next reading works flawless. I adaparted the Espruino Data Collection example to store the temp measurement of the TMP117 and the magnetometer of the puck.js board every 30seconds in memory and then export it out via bluetooth using a site to connect and download the logs. sorry for variable names :/ |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2019-07-26 by Robin Fri 2019.07.26 @user101989, Clever to adapt the Espruino Data Collection example adding data logging, visual feedback and use Bluetooth as a delivery means. A working complete solution nicely done! This is not necessary, and I am being real picky here, are L26 & L27 both needed, as it appears to be the same instruction, and I'm guessing one or the other isn't providing any use? In one, a string representation of hex zero is sent, the other a decimal representation. Did the Arduino documentation or sensor docs have any detail on what the argument for the write parameter should be? Normally, hex values are sent and not a string representation. It might be that One could spend hours attempting to 'fine tune' but it is really up to you. Nice project concept, and a complete project solution. Be proud that you were able to conquer and solve yourself. |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2019-07-26 by maze1980
This function is used quite often in the examples: |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2019-07-26 by maze1980 Is there any specific reason to write twice to the register 0 / Temp_Reg? I'd say for this device it should be only one line, like this |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2019-07-29 by @gfwilliams Glad you got this sorted! I'd definitely look at @maze1980's suggestions about using I2C though - it's much cleaner.
It'd be a great idea to add this suggestion from @robin (and to also change What you're actually doing there is defining a string of text rather than a number, so it'll behave quite differently if you do anything with it. As chance would have it JavaScript will convert this to a number properly for you, but if you try to use it in any other way you'll hit big issues. For instance |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2019-07-29 by user101989 Hej @gfwilliams @robin @AkosLukacs and @maze1980, thanks for taking the time to review my code and also for helping me improving it. I took the time to edit my code and include the suggestions, feel free to double check. This should store up to 2000 readings of the high accuracy TI TMP117 sensor into an array. Then you can download this data from the puck using a site with this code but before make sure you are running a node process with this code, it will listen to socket data and use Winston to dump it into the file system. |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2019-07-29 by user101989 Let me know if you want pics/help with connecting the TMP117 with the puck in the physical world. |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2019-07-29 by Robin Mon 2019.07.29 Very nicely done @user101989 and web page access bonus too!! As you have put quite a bit of effort into this project, and others would surely benefit, as it appears images could be part of the presentation, would you like to create a tutorial or a presentation and upload that to either the Tutorials or Projects headings? |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2019-07-29 by user101989 Yeah Ill do that. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2019-07-26 by user101989
I am trying to read from a i2c connect sensor. I managed to get my schematic and code working for arduino leonardo but not when I interface with the puck. I suck at bytes and low level stuff, so I am wondering if I understand what I am doing.
trying to imitate this:
i am getting a senseless value, i wonder what am I doing wrong? I find it hard to understand how to map these i2c operations to the pucks i2c api.
Beta Was this translation helpful? Give feedback.
All reactions