I2C does not work. OS Error
-
- Posts: 3
- Joined: Mon Jan 30, 2017 9:04 pm
I2C does not work. OS Error
Hello
I tried the following:
[code]
MicroPython v1.8.7-7-gb5a1a20a3 on 2017-01-09; ESP module with ESP8266
Type "help()" for more information.
>>> from machine import Pin, I2C
>>> gpio_scl=Pin(12)
>>> gpio_sda=Pin(14)
>>> i2c = I2C(scl=gpio_scl, sda=gpio_sda, freq=100000)
>>> addr = 0x03
>>> ch0 = '\x00'
>>> i2c.writeto(addr,ch0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 19] ENODEV
>>>
[/code]
Could someone help my to figure out, what the problem is?
Thanks
I tried the following:
[code]
MicroPython v1.8.7-7-gb5a1a20a3 on 2017-01-09; ESP module with ESP8266
Type "help()" for more information.
>>> from machine import Pin, I2C
>>> gpio_scl=Pin(12)
>>> gpio_sda=Pin(14)
>>> i2c = I2C(scl=gpio_scl, sda=gpio_sda, freq=100000)
>>> addr = 0x03
>>> ch0 = '\x00'
>>> i2c.writeto(addr,ch0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 19] ENODEV
>>>
[/code]
Could someone help my to figure out, what the problem is?
Thanks
Re: I2C does not work. OS Error
What does I2C.scan() show?
-
- Posts: 3
- Joined: Mon Jan 30, 2017 9:04 pm
Re: I2C does not work. OS Error
[quote="kfricke"]What does I2C.scan() show?[/quote]
Hi
Thanks for your answer.
I have my own hardware at the I2C Bus.
Therefore i2c.scan() will probably not show up something.
My hardware is a microcontroller (STM8) which is configured as I2C slave (hardware i2c not software).
It should only receive data from the ESP. Sure, it will also answer with NACK and ACK.
But what does this error mean: OSError: [Errno 19] ENODEV ?
Thanks
Hi
Thanks for your answer.
I have my own hardware at the I2C Bus.
Therefore i2c.scan() will probably not show up something.
My hardware is a microcontroller (STM8) which is configured as I2C slave (hardware i2c not software).
It should only receive data from the ESP. Sure, it will also answer with NACK and ACK.
But what does this error mean: OSError: [Errno 19] ENODEV ?
Thanks
Re: I2C does not work. OS Error
That error means that the ESP8266 has sent a start condition followed by the address of the device, but didn't receive an ACK after that.
The reasons for that may be many, but the most common one is that the i2c device is connected wrong -- for example the wires are swapped, there are no pullup resistors or the resistors are too weak, etc.
It's also possible, that the device in question simply didn't answer because it has a different address than the one you are trying (i2c.scan() should help diagnose that), has a bug in its code, expects a slower clock frequency (you can set that with the frequency parameter) or clock stretching timeout (you can set that with the timeout parameter), etc.
Unless you give us more details and check the things we asked you to check, we can just be guessing...
The reasons for that may be many, but the most common one is that the i2c device is connected wrong -- for example the wires are swapped, there are no pullup resistors or the resistors are too weak, etc.
It's also possible, that the device in question simply didn't answer because it has a different address than the one you are trying (i2c.scan() should help diagnose that), has a bug in its code, expects a slower clock frequency (you can set that with the frequency parameter) or clock stretching timeout (you can set that with the timeout parameter), etc.
Unless you give us more details and check the things we asked you to check, we can just be guessing...
Re: I2C does not work. OS Error
I was also baffled by this trivial error at first until I realised it is a simple factor of too much knowledge!
The I2C.scan() function returns the addresses not in Hex, but in good ol' decimal! I was getting the result [30] from the scan and trying to access the device on 0x30, turns out that it is at the conversion to hex of 30 decimal, 0x1E!
Try that the next time you get stuck with I2C addresses! So simple, but basically ruined my day until I realized!
The I2C.scan() function returns the addresses not in Hex, but in good ol' decimal! I was getting the result [30] from the scan and trying to access the device on 0x30, turns out that it is at the conversion to hex of 30 decimal, 0x1E!
Try that the next time you get stuck with I2C addresses! So simple, but basically ruined my day until I realized!
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: I2C does not work. OS Error
That is how the Python language works. scan() returns a list of integers. Integers are displayed in decimal by default: if you want to convert them to a hex string, you need to issue hex(my_integer).
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: I2C does not work. OS Error
I had a similar problem (also with I2C interface) and came here trying to figure out what Error 19 could be...
Thanks to you I realized I was not using the pull up resistors and now it's all fine. I am used to use "plug and play" modules that come with pull-up resistors, and now that I am building my own circuit I just forgot it...
Thanks
Thanks to you I realized I was not using the pull up resistors and now it's all fine. I am used to use "plug and play" modules that come with pull-up resistors, and now that I am building my own circuit I just forgot it...
Thanks
-
- Posts: 4
- Joined: Wed Feb 17, 2021 4:11 pm
Re: I2C does not work. OS Error
I am having the same problem, I have a pi piclo running microPython, with this simple code.
import machine
import utime
sda=machine.Pin(4)
scl=machine.Pin(5)
i2c=machine.I2C(0, sda=sda, scl=scl, freq=40000)
print(i2c.scan()) # this displays [39]
print("I2C Hex address "+ hex(i2c.scan()[0}).upper()) # this displays I2C address 0x27
i2c.reafrom(0x27,4)
print (i2c) #this displays I2C(0, freq399361, scl=5, sda=4
i2c writeto(0x27, '\x7C')
i2c.writeto(0x27, '\x2D')
i2c writeto(x,27, "Hello")
I get no errors, but nothing happens to the LCD. If I put a longer string "Hello world" then the display just goes blank. Exactly the same thing happens when I put in 39 in place of the 0x27. I have now spent 3 days and bought 3 new i2c LCD's from amazon and going nuts!
import machine
import utime
sda=machine.Pin(4)
scl=machine.Pin(5)
i2c=machine.I2C(0, sda=sda, scl=scl, freq=40000)
print(i2c.scan()) # this displays [39]
print("I2C Hex address "+ hex(i2c.scan()[0}).upper()) # this displays I2C address 0x27
i2c.reafrom(0x27,4)
print (i2c) #this displays I2C(0, freq399361, scl=5, sda=4
i2c writeto(0x27, '\x7C')
i2c.writeto(0x27, '\x2D')
i2c writeto(x,27, "Hello")
I get no errors, but nothing happens to the LCD. If I put a longer string "Hello world" then the display just goes blank. Exactly the same thing happens when I put in 39 in place of the 0x27. I have now spent 3 days and bought 3 new i2c LCD's from amazon and going nuts!
-
- Posts: 4
- Joined: Wed Feb 17, 2021 4:11 pm
Re: I2C does not work. OS Error
Gosh! I got two 1602 serial HD44780 and Geeek 2004 20X4. That mean anything ?