Open neuberfran opened 5 years ago
Hi there,
It looks like your python interpreter just can't find the usmbus module: how did you go about installing it?
You should be able to see the list of places python is looking for modules with:
import sys
print(sys.path)
I don't have micropython handy but having the usmbus
directory in the same directory as the main script, or in a subdirectory called lib
usually works.
I did not give any installation commands, I thought they were already part of the micropython kernel. Do you look at the OpenEletronics_i2c.py module? Will I have to make many changes to the code to stop using your smbus? Do you think I'd better adapt OpenEletronics_i2c.py with the micropython library machine?
Hi,
There are different ways you could tackle this, but it would help to know what you're trying to do: is there a particular sensor you're trying to use?
first of all, thanks for the help.
this is the sensor in case: http://www.mindsensors.com/rpi/76-smartdrive-high-current-motor-controller the original driver is python.
I made a driver for it in java: https://github.com/neuberfran/SmartDrive/blob/master/SmartDrive/src/main/java/com/neuberfran/androidthings/driver/SmartDrive/SmartDrive.java for android things,
and thought of doing in c ++: https://forum.arduino.cc/index.php?topic=619218.new#new
would be specifically pro esp32, but I prefer micropython
Can you help me more
I think this module can help you here - all you need to do is install it alongside the OpenElectrons_i2c.py
on your micropython board.
If you call it smbus
rather than usmbus
the code should run more or less without modification, I think (I'm by no means an expert). Depending on which pins you're using, you may need to modify the line that initialises the SMBus object:
I'm also not sure whether the ctypes
module will behave exactly as expected, but we can cross that bridge when we come to it :-)
the main issue is still at the beginning. how to install your module so I can import it?
I’m not sure how your environment is set up, so unsure what to suggest. Are you using a python board of some kind? How are you getting the openelectrons code onto it? As a brute force method you could just copy the SMBus class into your file above the openelectrons class
I'm trying to use usmbus SMBus on an esp32 with 30 pin espressif running micropython.
I already rode OpenElectrons_i2c on (and run motors with i2c smartdrive-drive) a raspberry pi 3 and an intel edison, but these two platforms ran normal python and not micropython, so I could use the modules smbus (python normal) and ctypes.
You said:"As a brute force method you could just copy the SMBus class into your file above the openelectrons class"
How can I do this? (pls)
How are you getting the openelectrons file onto your esp32 board at the moment? Do you have it connected via USB? When I'm developing on an esp8266 I have it connected via USB, and use the micropython IDE extension: https://marketplace.visualstudio.com/items?itemName=dphans.micropython-ide-vscode
This allows you to copy files onto the board, so to use usmbus.SMBus
you git clone
this project, and copy the usmbus
directory from this project into the /lib
directory on your board.
You said:"As a brute force method you could just copy the SMBus class into your file above the openelectrons class" How can I do this? (pls)
Something like this is what I was imagining: https://gist.github.com/gkluoe/83b11673484c1a8a4e555607ad52c362
@gkluoe
hi
https://github.com/neuberfran/SmartMPython
I would appreciate it if you continued to help me solve this project and make engines move. I created the file main.py, but it does one only error
Hi - the problem in this picture, I think, is that you're using python 2 syntax, and micropython is (roughly) Python 3. In python 3, you need to use the print()
function instead:
print("Batt: " + str(SmartDrive.getBattVoltage())
Should work. If you fix up all the print statements, hopefully that will help!
@gkluoe Tks I am evolving. While I bring more screenshots with updated issues:
Look:
(base) iMac:SmartMPython neuberfran$ ampy --port /dev/tty.SLAB_USBtoUART ls
/OpenElectrons_i2c.py
/SmartDrive.py
/boot.py
https://github.com/neuberfran/SmartMPython/blob/master/OpenElectrons_i2c.py
Hmm, OK, now I think your issue is here:
The ctypes
module doesn't exist on micropython. There is a uctypes module, but as far as I can tell, it doesn't offer the .c_int()
and .c_long()
functions that this code is using.
You could re-implement these functions - in theory that's quite simple - all they do is convert a python int
or long
into c-style signed number, but this is getting a bit over my head!
To be honest, at this point it's probably going to be easier to just rewrite the OpenElectrons_i2c.py module to work natively in micropython. I'd love to help with that but without your hardware to test on, I don't think I can.
https://github.com/neuberfran/SmartMPython/invitations
any PR will be welcome
Hi,
I need transpose this project:https://github.com/neuberfran/OpenElectrons_i2c/blob/master/OpenElectrons_i2c.py
from python to micropython, but I have issue: