<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[I2C slave mode doesn&#x27;t work for UnitV Stick]]></title><description><![CDATA[<p dir="auto">Any ideas how to establish a I2C connection with the M5Stack UnitV as I2C.Slave?</p>
<p dir="auto">Setup:</p>
<ul>
<li>M5Stack UnitV = I2C Slave</li>
<li>ESP8266 = I2C Master + Wifi</li>
</ul>
<p dir="auto">Setting up the UnitV Stick as a I2C slave is failing.  I'm connecting a ESP8266 with ports 34,35 of the UnitV and a 4,7kO Pull-Up resistor.</p>
<p dir="auto">The scan from the ESP8266 master is successful, but any read <s>or write</s> operation fails with a timeout message. The connection to other I2C devices is successful, when the UnitV is removed from the bus.<br />
<strong>UPDATE: Any write operation - before a read - is successful. After the first read, the bus is blocked.</strong></p>
<pre><code>import time
from machine import I2C

I2C_SLAVE_ADDR = 0x3a
count=0

def i2c_on_receive (data):
    print ("on_receive:", data)

def i2c_on_transmit ():
    count = count + 1
    print ("on_transmit, send:", count)
    return count

def i2c_on_event (event):
    print ("on_event:", event)

print ("starting i2c")
i2c = I2C(I2C.I2C1, mode = I2C.MODE_SLAVE, scl=34, sda=35,
            freq = 400000, addr = I2C_SLAVE_ADDR,
            addr_size = 7,
            on_receive = i2c_on_receive,
            on_transmit = i2c_on_transmit,
            on_event = i2c_on_event)
while True:
    time.sleep(20)
</code></pre>
<p dir="auto">ESP8266 Micropython Code:</p>
<pre><code>from machine import Pin, I2C
i2c = I2C(scl=Pin(12), sda=Pin(13), freq=400000)
i2c.scan()  # returns [58]
i2c.writeto(0x3a,'test') # success, write 4 bytes to slave with address 0x3a
result = i2c.readfrom(0x3a, 4)  # fails with Timeout
print(q)
</code></pre>
<p dir="auto">UPDATE 2020-06-26:</p>
<ul>
<li>Code Cleanup (remove ws2812 reference), add esp8266 code</li>
</ul>
]]></description><link>https://community.m5stack.com/topic/2067/i2c-slave-mode-doesn-t-work-for-unitv-stick</link><generator>RSS for Node</generator><lastBuildDate>Tue, 28 Apr 2026 20:41:12 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/2067.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 23 Jun 2020 18:22:38 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to I2C slave mode doesn&#x27;t work for UnitV Stick on Wed, 18 Nov 2020 05:04:05 GMT]]></title><description><![CDATA[<p dir="auto">Is this problem already solved?</p>
<p dir="auto">It seems to be a mistake in the sample program.</p>
<p dir="auto">Although, the variable 'count' in the function i2c_transmit() should be global, it is interpreted as local.</p>
<p dir="auto">I modified the function i2c_on_transmit() as follows:</p>
<pre><code>def i2c_on_transmit ():
    global count
    count = count + 1
    print ("on_transmit, send:", count)
    return count
</code></pre>
<p dir="auto">Then, it worked well.</p>
]]></description><link>https://community.m5stack.com/post/10782</link><guid isPermaLink="true">https://community.m5stack.com/post/10782</guid><dc:creator><![CDATA[TakekazuKATO]]></dc:creator><pubDate>Wed, 18 Nov 2020 05:04:05 GMT</pubDate></item><item><title><![CDATA[Reply to I2C slave mode doesn&#x27;t work for UnitV Stick on Sun, 28 Jun 2020 02:09:28 GMT]]></title><description><![CDATA[<p dir="auto">I2C problem seems from the maixpy. maybe you could commit a issues to maixpy github</p>
]]></description><link>https://community.m5stack.com/post/9171</link><guid isPermaLink="true">https://community.m5stack.com/post/9171</guid><dc:creator><![CDATA[m5stack]]></dc:creator><pubDate>Sun, 28 Jun 2020 02:09:28 GMT</pubDate></item><item><title><![CDATA[Reply to I2C slave mode doesn&#x27;t work for UnitV Stick on Fri, 26 Jun 2020 15:54:22 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/user/lukasmaximus" aria-label="Profile: lukasmaximus">@<bdi>lukasmaximus</bdi></a>,</p>
<p dir="auto">I want create snapshots with the UnitV via WIFI.   The ws2812 import is only to show the status of the camera.</p>
<p dir="auto">UnitV  = I2C Slave<br />
ESP8266 = I2C Master + Wifi</p>
<p dir="auto">Jan</p>
]]></description><link>https://community.m5stack.com/post/9162</link><guid isPermaLink="true">https://community.m5stack.com/post/9162</guid><dc:creator><![CDATA[jani]]></dc:creator><pubDate>Fri, 26 Jun 2020 15:54:22 GMT</pubDate></item><item><title><![CDATA[Reply to I2C slave mode doesn&#x27;t work for UnitV Stick on Thu, 25 Jun 2020 01:57:07 GMT]]></title><description><![CDATA[<p dir="auto">Why not just import the neopixel module if you are just driving some ws2812 rgb leds?</p>
]]></description><link>https://community.m5stack.com/post/9142</link><guid isPermaLink="true">https://community.m5stack.com/post/9142</guid><dc:creator><![CDATA[lukasmaximus]]></dc:creator><pubDate>Thu, 25 Jun 2020 01:57:07 GMT</pubDate></item><item><title><![CDATA[Reply to I2C slave mode doesn&#x27;t work for UnitV Stick on Wed, 24 Jun 2020 09:56:35 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/m5stack" aria-label="Profile: m5stack">@<bdi>m5stack</bdi></a> The deinit() is just called at the end for cleanup. I2C should work in the endless loop "while True: time.sleep(20)"</p>
]]></description><link>https://community.m5stack.com/post/9129</link><guid isPermaLink="true">https://community.m5stack.com/post/9129</guid><dc:creator><![CDATA[jani]]></dc:creator><pubDate>Wed, 24 Jun 2020 09:56:35 GMT</pubDate></item><item><title><![CDATA[Reply to I2C slave mode doesn&#x27;t work for UnitV Stick on Wed, 24 Jun 2020 03:19:08 GMT]]></title><description><![CDATA[<p dir="auto">i2c.deinit()? why you add deinit? that mean is close the I2C bus</p>
]]></description><link>https://community.m5stack.com/post/9120</link><guid isPermaLink="true">https://community.m5stack.com/post/9120</guid><dc:creator><![CDATA[m5stack]]></dc:creator><pubDate>Wed, 24 Jun 2020 03:19:08 GMT</pubDate></item></channel></rss>