ESP8266 i2c?

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
mianos
Posts: 84
Joined: Sat Aug 22, 2015 6:42 am

ESP8266 i2c?

Post by mianos » Sat Oct 24, 2015 11:42 pm

I was thinking of compiling the SDK provided i2c into my branch to talk to a DS3231 clock.
Does anyone have any thoughts? Should I hack the arduino one that already has a 'Wire' like interface or
start with the example SDK Esp one that is meant to actually work a bit and make a 'wire' interface on top of that?
Unfortunately I can'd just build the SDK example one out of tree as micropython has the warnings would up and the example one won't compile with the mp Makefiles so I'd probably have to copy it into the esp tree (license issues aside) and mod it a bit.

User avatar
platforma
Posts: 258
Joined: Thu May 28, 2015 5:08 pm
Location: Japan

Re: ESP8266 i2c?

Post by platforma » Sun Oct 25, 2015 12:24 am

I think it's always best to start with the stripped down version of SDK example and work from there. I doubt it'll compile straight away but don't just dump the whole thing in, start with a couple of new spi.c/h files, add it to targets in the Makefile and move functions across from the SDK example as you need them. Include any headers that you find in the SDK as normal because the include directory is already added to the Makefile. With a little bit of work you should be able to get going.

mianos
Posts: 84
Joined: Sat Aug 22, 2015 6:42 am

Re: ESP8266 i2c?

Post by mianos » Sun Oct 25, 2015 2:22 am

examples/driver_lib/driver/i2c_master.c is minimal already so I'll go from there.

mianos
Posts: 84
Joined: Sat Aug 22, 2015 6:42 am

Re: ESP8266 i2c?

Post by mianos » Wed Oct 28, 2015 9:19 am

After reviewing a bunch bit banging i2c libraries I went back to Wuxi's original Espressif one and re-wrote it.
As the ESP does not have i2c hardware it makes no sense to have the sda and scl pins hard coded in #defines
because you can use any and all available gpio pins for i2c. It's working as a master only from C so I'll try and make it look like
the existing python 'Wire' library (except you need to specify two pins and not one i2c port).
(My crappy little $3 chip now has, 2 DHT22s, two working i2c buses, frozen modules from rom, esp timers, mutexes, esp os tasks and interrupt driven GPIO :)

User avatar
kfricke
Posts: 342
Joined: Mon May 05, 2014 9:13 am
Location: Germany

Re: ESP8266 i2c?

Post by kfricke » Wed Oct 28, 2015 4:26 pm

mianos wrote:... As the ESP does not have i2c hardware it makes no sense...
Really? According to chapter 7.3 of the SDK Programming Guide i did assume that the C API does access real hardware internally :?
(My crappy little $3 chip now has, 2 DHT22s, two working i2c buses, frozen modules from rom, esp timers, mutexes, esp os tasks and interrupt driven GPIO :)
Really cool! I do also like that little platform, but personally have not had the time to throw those pieces together.

Do you mind writing a little 50 word step-by-step guide to plug together the ESP build with frozen modules etc.? Such an article might be a good sticky post to introduce a real "ESP platform" subforum.

mianos
Posts: 84
Joined: Sat Aug 22, 2015 6:42 am

Re: ESP8266 i2c?

Post by mianos » Wed Oct 28, 2015 9:30 pm

kfricke wrote:
mianos wrote:... As the ESP does not have i2c hardware it makes no sense...
Really? According to chapter 7.3 of the SDK Programming Guide i did assume that the C API does access real hardware internally :?
That's a LOL. That 'API' is just a bit of bit banging a couple of arbitrary (hard coded) GPIO ports for i2c. I just started with the actual code in the SDK and re-wrote it to create and pass around a struct that has the ports and context. At least using their sdk the timing is going to have been tested, a bit.
Do you mind writing a little 50 word step-by-step guide to plug together the ESP build with frozen modules etc.? Such an article might be a good sticky post to introduce a real "ESP platform" subforum.
I'll do that when I finish the i2c python integration. It's easy now if you have the SDK set up. You just create a module in scripts/main.py.
For my version these are stored in irom0 so you can pretty much have unlimited modules.

If I don't get a day job, what I'd like to try next is use the tcp module to load new scripts via tcp into my frozen structure in irom, then I could have a binary flashed but arbitrary python.
Because the tcp stack uses callbacks, the way I am thinking will be do have a normal main something like this always frozen:

Code: Select all

import esp.tcpmodloader

def imdone():
    import mymainrunner
    mymainrunner.run()

def main():
   ml = esp.tcpmodloader('192.168.1.1', done=imdone)
   ml.load('/moyamodules/crap.py')
 

Post Reply