[Errno 19] ENODEV

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
jf7899
Posts: 6
Joined: Wed Jun 16, 2021 1:24 pm

[Errno 19] ENODEV

Post by jf7899 » Wed Jun 16, 2021 2:54 pm

Hi,
I'm using a HMC5883L magnetic sensor and a ESP32-PICO-KIT, I'm having trouble trying to run the following code

Code: Select all

import machine
import utime
i2c = machine.I2C(scl=machine.Pin(26), sda=machine.Pin(25),freq=100000)
i2c.start()
i2c.writeto(0x3C, bytes([0, 112]))
i2c.writeto(0x3C, bytes([1, 176]))
i2c.writeto(0x3C, bytes([2, 0]))
utime.sleep(6)

def loop():
    while True:
        B=i2c.readfrom(0x3D,0x06)
        print(B)
try:
    loop()
except KeyboardInterrupt:
    i2c.stop()
    print('Got Ctrl-C')
finally:
    print("Finishing...")
    
The error I'm getting is

Code: Select all

Traceback (most recent call last):
  File "main.py", line 6, in <module>
OSError: [Errno 19] ENODEV
MicroPython v1.12 on 2019-12-20; ESP32 module with ESP32
Type "help()" for more information.
Can someone help with this?
Thank you all for your time.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: [Errno 19] ENODEV

Post by Roberthh » Wed Jun 16, 2021 3:14 pm

that looks like a connection problem. What is returned by i2c.scan()?
Note: You do not need i2c.start()

jf7899
Posts: 6
Joined: Wed Jun 16, 2021 1:24 pm

Re: [Errno 19] ENODEV

Post by jf7899 » Wed Jun 16, 2021 3:24 pm

Frist of all thank you for the reply,
In the datasheet of the HMC5883L it sates that using i2c.scan() it returns an array with zero lenght, wich we verified that indeed happens.
So you think the problem is hardware related, some sort of techical malfunction?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: [Errno 19] ENODEV

Post by Roberthh » Wed Jun 16, 2021 3:38 pm

If the returned list is empty then there is a connection problem. It should show the I2C address of the device, 0x3c or 60 decimal. Please check, that you connected SDA, SCL, GND and Vcc properly.

jf7899
Posts: 6
Joined: Wed Jun 16, 2021 1:24 pm

Re: [Errno 19] ENODEV

Post by jf7899 » Wed Jun 16, 2021 4:05 pm

Once again thank you for the reply.
The datasheet of the HMC5883L states that The address pointer value itself cannot be read via the I2C bus.
Any attempt to read an invalid address location returns 0’s, and any write to an invalid address location or an undefined bit
within a valid address location is ignored by this device.
Doesn't that mean that the i2c.scan() should indeed return a empty array?

With respect to the conections I have double checked and I think that everything is alright, nevertheless there is a picture of the circuit in the attachments. The order of the pins in the HMC5883L in order of up to down is GND, VCC, SDA, SCL. Hope it can help you helping us.

Cheers
Attachments
200293877_956092011840819_5870976956692029262_n.jpg
200293877_956092011840819_5870976956692029262_n.jpg (97.82 KiB) Viewed 2832 times

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: [Errno 19] ENODEV

Post by Roberthh » Wed Jun 16, 2021 4:36 pm

No. Address pointer refers to the register stack of the HMC5883L. The picture is hard to read, especially the numbers of the board. But it looks like you swapped SDA and SCL.

jf7899
Posts: 6
Joined: Wed Jun 16, 2021 1:24 pm

Re: [Errno 19] ENODEV

Post by jf7899 » Wed Jun 16, 2021 4:45 pm

You were right, indeed, we have them changed, thank you very much! Nevertheless it doesn't fix the error and the i2c.scan() still returns a empty array... Do you have any other ideas?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: [Errno 19] ENODEV

Post by Roberthh » Wed Jun 16, 2021 5:05 pm

Whar are the values of the resistors you've added? What are the colors? And it seems that on the HM5883 breakout there are resistors too.

jf7899
Posts: 6
Joined: Wed Jun 16, 2021 1:24 pm

Re: [Errno 19] ENODEV

Post by jf7899 » Wed Jun 16, 2021 5:15 pm

Thank you for the response.
The resistor values are 2.2kohms each. I did not uderstand what you meant by "it seems that on the HM5883 breakout there are resistors too",does that mean we don't need to use external pull-up resistors?
In the attachments I'm sending a closer picture of the sensor and the internal schematic diagram of it as it is shown in the datasheet.
Attachments
Capturar.JPG
Capturar.JPG (74.9 KiB) Viewed 2803 times
200334919_502624907524707_3435836658574032814_n.jpg
200334919_502624907524707_3435836658574032814_n.jpg (78.34 KiB) Viewed 2803 times

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: [Errno 19] ENODEV

Post by Roberthh » Wed Jun 16, 2021 5:21 pm

If I see the colors right, the rings on the resistor are red red gold gold, This is 2.2 Ohm. 2.2K has the colors red red red gold.

Post Reply