Digital comms always fail

Hey,

First off, I’d like to say that I really love the Imp platform! That’s why it’s so unfortunate to have to resort to inferior chips in order to resolve some of the Imp’s own issues.

In my personal experiences (most of which are documented on the forums), I’ve had absolutely no success getting any of the digital communication protocols to work… Be it i2c, SingleWire (for the DHT22), etc.

In addition, I’ve also had very unreliable results when doing pin.read() on analog pins.

I’m 100% sure that my wiring, hardware & (quite possibly) code is correct since I got the same exact sensors (TMP102, DHT22, etc.) to work on the Arduino with absolutely no issues whatsoever.

I was eventually forced to drop in an Arduino in my setup to just take care of the sensor communication and relay the data via UART to the Imp, but it’s really annoying to have to add additional hardware and complexity for something so trivial as i2c.

Can anybody relate to this and if so, how did you manage to fix said issues?

Any help would be greatly appreciated!

I can relate to the experience of working on a problem and becoming frustrated for one reason or another. certainly.

however, I have not had any trouble with digital on the imp. I have used i2c, SPI and UART. I’ve used imp001 and imp002. I am relatively inexperience so I do have to use the Google.

The biggest problem I have encountered is that certain connectors and some old imp001 had trouble making a connection on Pin1. if you have really old hardware then I suggest doing a simple test to check the integrity of pin1 connection.

Do you have a scope or logic analyzer? If your signal quality is good then you can double-check the results of your code by using a logic analyzer.

I have the Logic8 from Saleae and have found it to be incredibly useful in some other projects. I have not had to use it on an imp project yet.

I also use Arduino/AVR. These are quite different devices and also very good imo.

Hey and thanks for posting!

Sadly I don’t have a scope or logic analyzer on hand so I can’t really dig into the actual communication on the pins :frowning:

UART seems to be working fine, as noted, but I can’t get my head around how the TMP102 for example always returns NILL on the Imp and works flawlessly when hooked up to an Arduino.

The same with the DHT22.

I was initially thinking that I had some faulty sensors or perhaps the Imp breakout was misbehaving (as you noted), but I tried several different pin combinations to no avail :frowning:

Also, some other forum members said that they experienced similar issues when trying to interface with both of these sensors.

And it’s even stranger that pin.read() seems to produce (at least for me) very inconsistent results when polling even a simple photoresistor setup.

p.s. I’m not dissing the Arduino by any form - I just believe that platforms like the Imp are the shape of what’s to come and offer a lot more flexibility and features. That’s why it’s very hard for me to settle that I have to include a 328 chip just to get at a couple sensors’ data…

Thanks again for your input!

@tldstyl3, are you using our classes for these sensors. If not, they might well be worth checking out:

DHT22

and

TMP1x2

The DHT22 has a proprietary protocol and in my experience these can be tricky to implement because getting the timing right can be crucial.

Hey, @smittytone

Yes, I did, in fact, try those libraries (among any other I could find) and they all produced the same result…

Here are the threads I posted to about the sensor issues:

https://discourse.electricimp.com/discussion/comment/18942

https://discourse.electricimp.com/discussion/comment/14381#Comment_14381

I see that you even replied to one of those and I ended up trying other pins on the Imp, as you suggested, but to no avail…

@Hugo also tried to help out, but in the end he referred me to another sensor (as opposed to the DHT22).

What worries is me that the sensor he referred me to is also i2c and I couldn’t get the TMP102 to display anything with the Imp (whereas it’s currently working fine when hooked up to an Arduino).

Thanks very much for taking the time to post!

FWIW, I use i2c all the time for displays and sensors. I haven’t tried the TMP102 but I believe it is sensitive to the set-up so you may find that other things work even when it doesn’t appear to.

Oh, just check the i2c address on the TMP102. For the imp, you need to set the address to the data sheet << 1, e.g.

local impAddress = datasheetAddress << 1

I got bitten a few times early on by this need to convert a 7-bit i2c address into and 8-bit value with bit zero used for the i2c read/write bit.

Hey,

Yes, I believe I did the shifting when I tried the TMP102 to no avail.

It seems I’m stuck with the Imp + Arduino combo for now…

I was wondering whether this is more of a global problem rather than an isolated sensor issue when you factor in the inconsistent pin.read() results on Analog.

According to Adafruit, “You will want to place a 10K resistor between VCC and the data pin, to act as a medium-strength pull up on the data line”, i.e. between the imp’s 3V3 and Pin 2 (rather than between Pin 2 and Pin 7).

I think I would follow that layout (here) and use the Adafruit Arduino code by converting it to Squirrel, which looks relatively straightforward (guidance here) and reads the sensor from the pin rather than SPI.

@tldstyl3 - just jumping in here a moment re: your analog.read() issue. I don’t use analog a lot, but do seem to recall a few forum threads with similar comments. (@Hugo or others would probably have to comment further, but I’m seem to vaguely recall something about sampling noise, etc.)

This recent thread suggested possibly a little capacitance on an analog input might be beneficial to mitigate any noise (internal or external) a bit to yield more stable readings.

Again, not a lot of personal experience here, but it’s something you might want to consider or look into further.

@smittytone - Yes, I followed that same wiring when trying to get anything out of my DHT with the Imp using the available classes, but got nothing but errors & timeouts.

Short of writing my own class (which I’m not sure I would be able to even if I tried) I don’t see what else I can do to make this work.

Thanks for your help!

@LarryJ - Thanks for sharing that! I do recall similar comments back when I was trying to do analog reading with the Imp, but I could never quite get it to work consistently…

Perhaps I’ll try and have a go at it again soon if the need arises.

Thank you!

Ok, good luck @tldstyl3. The cap is just a ‘quick and dirty’ add that may help you out, but it looks like there’s a lot of good info here if needed. Might be overkill for your application, but indicates good general analog design practices. (Primarily the power supply stuff for what you’re doing I’d think).