Chat freely about anything...
User avatar
By batstru
philbowles wrote:OK. I'm not sure if this is anything to do with the sensor at all, but since you havent described or shown your wiring, it's just a guess.

Thanks for your answer, let me post my wiring.
While programming
ESP01 RX --> FTDI232 TX
ESP01 GPIO2 --> No connection
ESP01 Vcc --> Vcc (+3.3V)
ESP01 RST --> No connection
ESP01 CH_PD --> Vcc (+3.3V)
ESP01 TX --> FTDI232 RX

While testing with the sensor

ESP01 RX --> FTDI232 TX
ESP01 Vcc --> Vcc (+3.3V)
ESP01 RST --> No connection
ESP01 CH_PD --> Vcc (+3.3V)
ESP01 TX --> FTDI232 RX

By the way I guess wiring is fine, as the i2c scanner detects the sensor and it gives me the id.

philbowles wrote:It's a timing problem - something is interfering with or corrupting the serial output.
Look at the "gibberish" - the line of KKKK etc - there are 36 of them - the code shows you'd be expecting 36 "-" characters. Now look at the ascii values of each: "-" is 00101101 so a string of them would look like: 00101101001011010010110100101101 etc. K is 01001011 - 36 of them would start: 010010110100101101001011. Now look at the patterns:

"-" =00101101001011010010110100101101
"K"=xxxxxx010010110100101101001011 shifted by six characters....its the same

also the last part of the "junk" is the serial number etc...

so somehow you are losing 6 characters (48bits) of serial output somewhere...somehow. We need to see your wiring and/or power supply etc

Wiring is above, the power supply comes from the usb port of the notebook, via the FTDI232.

philbowles wrote:First of all, change the Serial speed to something a little more "modern" - make it 74880 as then you will see the ESP8266 boot messages too. It also changes the timing, so we can see if the dodgy output changes too...

This is the output I get at 74880 baud:
Code: Select all ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d

philbowles wrote:Put a tiny delay() here - to give some "settling time"

Code: Select allmag.getSensor(&sensor);

I'm rubbish at maths and lazy, but the ??? needs to be AT LEAST what 48bits @ 9600 baud takes...someone do the maths for me would you?

Either way keep the value as small as possible or you may cause other problems...
try several different values, e.g. start at 500 and then try 250 or 125 etc and go down as low as you can

AND show us your wiring.

I did some changes in the code adding the a delay of 500ms as you suggested, and a couple of statement to debug. It now hangs at "before".

This means the code gets stuck at mag.getEvent(&event);

Code: Select allvoid loop(void)
  /* Get a new sensor event */
  sensors_event_t event;

philbowles wrote:The code says 2 pins are required for the I2C - which are you using? What does Adafruit_HMC5883_Unified default to?

The more I think about this, the more I think its a wiring problem! Where does your sketch identify the pins that are used by the device? There aint many on an ESP01..your SDA / SCL are going to have to be on GPIO / 2 somehow - How does the Adafruit library know that?

See the wiring sketch I pasted above.

Any feedback?

Thank you, I feel closer to a solution :-)
User avatar
By batstru
philbowles wrote:I can't do this piecemeal - it's just guesswork. Please post the whole code.

What are the values of your pullups on SDA / SCL ?

Hi, I have a direct link between the ESP01 GPIO and the sensor, without any pullups resistors.
Is this wrong?
User avatar
By McChubby007
#72403 I've had a look at the adafruit library that you are using, and the code could hang (infinite loop) if it doesn't receive 6 bytes back from the sensor in Adafruit_HMC5883_Unified::read ... while (Wire.available() < 6);

That appears to be the only place it could hang in the getEvent call so I suggest it is not receiving enough data. I would make a change to the library and add a timeout so that it does not loop indefinitely (I HATE rubbish code like that... Thanks Adafruit!!). Or as a cheap and nasty, just return from the read early to prove where it is hanging.

This would of course point to a hardware problem.

Please do NOT ask for the code to do a timeout as it is rudimentary stuff.