Has anybody made a Teensy 3.0/3.1 respond as an i2c slave like a ds3231?

Status
Not open for further replies.

MichaelMeissner

Senior Member+
I have a Raspberry Pi, and I've been thinking about hooking up a Teensy to it to do neopixels, etc. One of the components of my Pi setup is to use one of the cheap ds3231 real time clocks to allow the pi to set the local time when booting when NTP is not available. Now, I could continue to have both the Teensy and the RTC on the i2c bus, but if I could make a Teensy 3.0/3.1 use its real time clock (with the backup coin battery) and interact on the i2c bus like a ds3231 would, I wouldn't have to include the RTC.

I'm still mulling over whether it would be better to use the external RTC (which is more accurate due to the temp. conversion) and use a Teensy LC to avoid having to do level conversion for the neopixels or go the 3.0/3.1 route and drop the RTC, adding level conversion. I don't need the advanced support of the ds3231 (EEPROM, interrupt support, etc.), all I need to do is interact with the Pi's hwclock command to read the current time and set the current time.

Yes, I'm aware of the kernel driver on the Pi to do neopixels, but every so often, I see complaints that it stopped working when doing updates, and I'm already familiar with the Teensy way of doing things.
 
So far, I'm not aware of anyone doing exactly this.

The Wire library supports slave mode. I believe it should be able to listen for I2C from the Raspberry Pi. It might take quite a bit of work to completely implement the DS3231 with the Wire library functions, but a usable subset might not be too much work. If you do get it working, I hope you'll post the code for others. That could be pretty useful, probably for regular Arduino too.

The Wire slave mode does use interrupts. That might not play well with the Adafruit_Neopixel library, which disables interrupts for the duration of the WS2811 output data. The OctoWS2811 library should be much more compatible.
 
Thanks. I would anticipate using the RTC only when I boot the Pi to set the time if network time is not available, so interrupts per se should not matter (while the pi is booting, it won't be sending out neopixel requests). And I'm not doing a video wall, so the number of neopixels that I will control will be fairly low (under 50).

My application with the Pi is what I call the Cambridge camera, where I stuff a Raspberry Pi into a Polaroid 95A camera body (Polaroid's headquarters used to be Cambridge, MA and the Pi was designed in Cambridge UK) and put Pi camera on the front. In the next generation, I was thinking of adding neopixels that would normally run random light patters but when I'm taking a picture would be all white to bring up the exposure levels when I'm shooting indoors at subjects close by. Or possibly the neopixels won't add enough light, and I will need to control strong LEDs via MOSFET and just use the neopixels for show. If I do the RTC in the Teensy 3.0/3.1, I need to add the level converters for running neopixels at 5v, but if I'm running the LC I don't need the level converter, but would need the RTC.

Since I'm only building a one off design, and I have all three of the Teensy variants, level converters, and RTC's in my toolbox right now, it is more what is more convenient. Right now, I'm leaning more towards using the LC, since I wouldn't have to dig in and learn the protocol.

Here are pictures of the current Cambridge camera. I'm replacing the Pi camera with a 3rd party camera with a faster lens, but even so, I believe I will need extra lights to actually take usable pictures indoors.
2015-02-23-10-30-001-hidepi.jpg

2015-02-23-10-42-002-hidepi.jpg
 
Would it not be a better option to use the teensy in rawhid mode and connect the rpi to the teensy via USB. That way you use only one cable and can get more data out in one packet if you wanted.
 
I've made an AtMega16 into an I2C slave and I would positively boggle if doing so with any Teensy was any more difficult than what I found, and utilised, to do it with that old favorite of mine (first one I ever programmed, my success level immediately made me lead programmer with my current employer.)

Can't see why I wouldn't be happy to post the code if prompted, it is (or at least, may be) reasonably AVR centric but, the required conversation isn't too obscured by the method it is using, pretty sure.

Probably shouldn't bother mentioning it because the wire library's slave stuff is most likely perfectly usable, anyway, by posting I have subscribed and I am willing to at least hope I can help your pursuit here :)
 
Just to be clear, yeah I can use other means of communication (such as serial port, raw HID, acting as a keyboard/mouse etc.).

I was thinking about i2c so that it would plug in to the framework the Pi already has for the hwclock program. Having something else, that eventually calls date in superuser mode to set the date can be done.

I also knew about slave mode, and I assumed it was functional on the Teensy. I was just hoping somebody had written the code to emulate the ds3231 protocol. There would not be Arduino code that does this, since the standard AVR arduiino and arduino-like board does not have a built-in real time clock that has an independent battery so the RTC is powered when the microprocessor is turned off. The Teensy 3.0/3.1 has these if you solder in a 32k crystal and a coin battery (but the LC doesn't have the infrastructure for this).

Given you can buy a DS3231 from merchants with US shipping for $4.50 ($1.02 if I was willing to wait for e-packet delivery from China), it doesn't make much sense to spend a lot of time trying to replicate it (hence the query to see if somebody had done it). In my case, the DS3231's are the wrong size, because they won't fit in the protoboard (Adafruit Perma-proto hat) I was going to attach the Teensy or other microprocessor to, but I can just attach it via cable and strap it down so it doesn't move.
 
Last edited:
Status
Not open for further replies.
Back
Top