Problems with Mycropython 1.10 threading i2c in th e pyboard

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
kapoira
Posts: 5
Joined: Sun Mar 17, 2019 12:29 pm

Problems with Mycropython 1.10 threading i2c in th e pyboard

Post by kapoira » Sun Mar 17, 2019 12:46 pm

Hello to all, first i explain the idea of my project,
it's to use a NeoTrellis RGB Driver PCB for 4x4 Keypad ( https://www.adafruit.com/product/3954)
from adafruit with the micropython (NOT circuitpython i know'it), and in the future to use with the k210 that have the micropython inside
https://www.seeedstudio.com/Sipeed-MAix ... -2872.html

I have found the python deprecated from adafruit and documentation with circuitpython, and i was trying to port this RGB driver and use with micropython

i have a pyboard v1.1 and i have update the firmware to
pybv11-thread-20190125-v1.10.dfu

My problem is with the documentacion https://docs.micropython.org/en/latest/ ... .mem_write

and in my main.py is this code:

import pyb
from machine import I2C
pyb.LED(4).on()
i2c = I2C(1)
i2c.scan()
[46]

the problem is when i want to talk to i2c i have found this error

>>> i2c.mem_write(0x7F,46,0x00)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'I2C' object has no attribute 'mem_write'

What i'm doing wrong? and if you see an easy form to translate the circuitpython i2c to micropython tell me, many thaks in advance.

(sorry english it's not my first language)

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

Re: Problems with Mycropython 1.10 threading i2c in th e pyboard

Post by Roberthh » Sun Mar 17, 2019 1:06 pm

You looked at the pyb.I2C class, but you are using the machine.I2C class, which is preferred for new code. The two classes differ a little bit: docs.micropython.org/en/latest/library/machine.I2C.html

kapoira
Posts: 5
Joined: Sun Mar 17, 2019 12:29 pm

Re: Problems with Mycropython 1.10 threading i2c in th e pyboard

Post by kapoira » Sun Mar 17, 2019 8:45 pm

Ok, 1 problem solved,

Now my problem it's that i always when i do a read in the i2c the response is 0xff

Anybody have tried the NeoTrellis RGB for 4x4 with the Micropython?

kapoira
Posts: 5
Joined: Sun Mar 17, 2019 12:29 pm

Re: Problems with Mycropython 1.10 threading i2c in th e pyboard

Post by kapoira » Mon Mar 18, 2019 10:47 pm

1 problem solved, another pushes from the back:

In micropython in the pyboard i don't know how to do something like this.

In the neotrellis is using a seesaw with i2c and it's seems to obtain a register i have to do two reads sequentially,

i copy the information about the seesaw: (the write are similar)


A register read is accomplished by first sending the standard I2C write header, followed by the two register bytes corresponding to the data to be read. Allow a short delay, and then send a standard I2C read header (with the R/W bit set to 0) to read the data.

The length of the required delay depends on the data that is to be read. These delays are discussed in the sections specific to each module.

In code, this may look like this (using the Arduino wire I2C object):

Code: Select all

void Adafruit_seesaw::read(uint8_t moduleBase, uint8_t moduleFunction, uint8_t *buf, uint8_t num, uint16_t delay)
{
    Wire.beginTransmission((uint8_t)_i2caddr);
    Wire.write((uint8_t)moduleBase); //module base register address
    Wire.write((uint8_t)moduleFunction); //module function register address
    Wire.endTransmission();
 
    delayMicroseconds(delay);
 
    Wire.requestFrom((uint8_t)_i2caddr, num);
 
    for(int i=0; i<num; i++){
        buf[i] = Wire.read();
    }
}

To translate this to the machine i2c in micropython python how can i do it?.

I'm trying to use the Memory operations
Some I2C devices act as a memory device (or set of registers)

But i don't know how to say 2 registers i have tried:

i2c.readfrom_mem(46,0x00,1,addrsize=8)
i2c.readform_mem(46,0x0000,1,addrsize=16)

and only obtain 0xFF

46 is the address of the seesaw (i have obtained with i2c.scan())
in the pyboard with the implementation of machine i2c how i can do it?

kapoira
Posts: 5
Joined: Sun Mar 17, 2019 12:29 pm

Re: Problems with Mycropython 1.10 threading i2c in th e pyboard

Post by kapoira » Sun Mar 24, 2019 11:01 pm

I have continued working with the problem and at last i have obtain a code that seem's to be working

At least the neopixel (writes with i2c seems to be OK) with the neotrellis i have to write the color and after that read another register to show the change in the led

but i'm seeing another problem in the reads seems that sometimes i have to do two reads, in the same register to obtain the good valor

I put the examples with pyb, but with machine i have the same problem

>>> import pyb
>>> from pyb import I2C
>>> import time
>>> i2c = I2C(1)
>>> i2c.init(I2C.MASTER, baudrate=50000)
>>>
>>> print(i2c.scan())
[46]
>>> print(i2c.is_ready(46))
True
>>> time.sleep(2)
>>> print("Es la primera lectura del chip_id")
Es la primera lectura del chip_id
>>> print(i2c.mem_read(1,46,0x0001,timeout=10000, addr_size=16))
b'\xff'
>>> print("Es la segunda lectura del chip_id")
Es la segunda lectura del chip_id
>>> print(i2c.mem_read(1,46,0x0001,timeout=10000, addr_size=16))
b'U'


the changes with the micropython i think that they are thinking to do two reads because the use registers of 8 bits (like in the arduino) and i use 0x001 with addr_size=16

Any ideas? or any tests that i can do?

Post Reply