Hey guys, so im attempting to set up an i2c communication from my esp32 to control my pim613 (Servo 2040) controller. The problem is when i scan for addresses i keep getting random returns. I feel like im getting 20 different addresses found and it cycles from that to saying no device found, i dont have a stable return address. Any ideas?
Did you setup the Servo 2040 as a slave device? Assuming thatâs possible.
I dont believe i did! I never thought of that while using i2c. Ive only ever did that with HC05. How does one set it to slave mode?
That I donât know? Thatâs above my current skill level. I know just enough about i2c to know âthere can be only oneâ host.
@Sherlock91: search around in the forum. Using a Pico as an I2C slave pops up every few weeks, there are a few links available pointing to I2C-slave implementations. One member of this forum (@maltheim ??) has written a basic one himself.
You could also just use Google and search for a MicroPython I2C slave implementation for the Pico.
Some other ideas: use the I2C pins as UART and connect either a HC05 for BT remote control or a suitable ESP running AT firmware. In the latter case you use the ESP as a wifi co-processor under full control of the servo2040. I.e. the ESP32 is not controlling the servo2040. Depending on your needs (especially what kind of tasks the ESP32 has in addition) this might be a much easier solution.
The code youâre referring to can be found at:
It is an I2C Slave implementation for the RP2040 based on a partial (but functional) code. The âi2c_slave.pyâ file defines an I2CSlave class. As an example, the âi2c_driver.pyâ file defines an I2CDriver subclass that overrides one of the methods in the slave class to add whatever functionality is desired.
This is a fairly limited implementation. It can send up to 32 ASCII characters from master to slave, with the slave returning a single byte as a result code.
To use this for your own purposes, youâd copy the basic functionality of the I2C Driver and override the process_payload()
method. To test, youâd copy âsend.pyâ over to your Raspberry Pi (as master) and use it to send messages to your RP2040 slave device.
send.py "This is my message."
Hopefully the documentation on the github repository is enough to get you going.
[I read this situation wrong because I didnât know much about the PIM613.]
Normally, if youâre connecting an I2C sensor, motor controller, servo controller, etc. as a device on an I2C bus, those are all I2C slave devices. But it sounds like the PIM613 is actually a âstandaloneâ I2C master controller, not an I2C slave. If you want to use it to control servos it sounds like youâre meant to program it, not connect it as an I2C slave. A device cannot be both a master and a slave. You could in theory connect other devices like sensors to the PIM613 as slave devices.
So if youâre using an ESP32 as a master, it is effectively trying to connect to the PIM613 as another master on the bus. That isnât going to work. If you want to communicate between the ESP32 and the PIM613 youâll likely have to use something like a UART.
Alternately, you could copy all the code from your ESP32 over to the PIM613 and use it as your main controller, since thatâs how it seems like itâs meant to be used.
Thank you for your replies. How would i use UART? It seems to only have the i2c pins and im at a complete loss on how theyd build a stand alone servo driver without a way to control it remotely. My initial work around was to use the BT or WIFI on the esp32 to connect to a controller or build an app
Could this method be used to attach an esp32 and utilize its ability to transmit a signal to connect a wireless controller? Thats my end game. Id like a way to control the movement of my hexbot and theres no clear direction available
Itâs a bit beyond the scope of this forum (or my time) to provide a complete description of how to use a UART with an ESP32, but thereâs plenty of documentation online about how to do that. How will depend upon your choice of programming language.
If youâre using MicroPython, UART functionality is built into the language, but also depends upon which microcontroller family youâre using. The ESP32-specific documentation can be found at: Quick reference for the ESP32 â MicroPython latest documentation
If you have the option of communicating between two ESP32 devices you can use a variety of methods, including Bluetooth, ESP32 WiFi, ESP32-Now, and ESP32 mesh. If youâre trying to communicate between an ESP32 and your PIM613, a UART is probably your best bet. Youâll have to develop the protocol to talk between the devices because there is no single standard way. But itâs just serial-to-serial, and again, thereâs lots of information online how to communicate via UART.
You can repurpose the I2C pins as UART pins. Then you could connect lets say an ESP32C3 to this UART, using the instructions in Get Started - ESP32-C3 - â ESP-AT User Guide release-v3.3.0.0 documentation. I have not tested it yet, but the ESP32C3 SuperMini is claimed to work already with 3V3, so you would use a Stemma/QT to DuPont cable to connect the systems.
You also need a library that uses the AT command set from the servo2040. Something like GitHub - myvobot/pi_pico_wifi_driver: A simple driver using AT command to access WiFi/Internet on the Pi Pico. I have no idea if this is the best library you can get, but Google is your friend.
That makes sense, never thought i could change them to UART Just waiting for my jst cable to come in for the qwiic connection and ill be diving into your explanation! Ill update with results! Thank you!