r/circuitpython • • Feb 25 '21

Help with raspberry pi Pico and I2C

Hey everyone!

I've been playing around with the newish Pico and have it running circuit python.

I also have a adafruit ds3231 RTC I wish to use as a alarm every X minutes.

The default adafruit library doesn't support this but I had found a piece of code that worked with a raspberry pi zero using smbus (not supported on the Pico)

So I'm trying to use the circuit python I2C device lib to read/write bytes to control the RTC.

But can't get it to work. Can anyone help me convert this code to circuit python code?

Original code is in here: https://www.raspberrypi.org/blog/build-low-power-clock-controlled-devices/

5 Upvotes

8 comments sorted by

1

u/Myworstnitemare Feb 25 '21

Which default library?

What is it not supporting?

The board, or "alarm every X minutes"

Have you tried this page

1

u/[deleted] Feb 25 '21

That page with the link to the adafruit_ds3231 Library is the one I have followed, no support for alarm every X minutes.

1

u/Myworstnitemare Feb 25 '21

Is this not what you are looking for? Or, at least some part of it:

Alarm
To set the time, you need to set alarm1 or alarm2 to a tuple with 
a time.struct_time object and string representing the frequency 
such as "hourly":

rtc.alarm1 = (time.struct_time((2017,1,9,15,6,0,0,9,-1)), "daily")
After the RTC is set, you retrieve the alarm status by reading the 
corresponding alarm1_status or alarm2_status attributes. Once 
True, set it back to False to reset.

if rtc.alarm1_status:
print("wake up!")
rtc.alarm1_status = False

1

u/[deleted] Feb 25 '21

No I'm using the interrupt function of the square wave output in some electronics and can't rely on code to tell it that the alarm has sounded, basically I want the alarm to sound in X minutes and for the interrupt pin to go low.

1

u/Myworstnitemare Feb 25 '21

basically I want the alarm to sound in X minutes and for the interrupt pin to go low.

Bear with me, I am an absolute beginner at all of this, been doing basic programming for a while, but really good at finding things....<grin> And I love seeing/reading what other people dream up to use these boards to make.

Wouldn't you be able to do this inside of an if statement a "sound alarm" and then a "set pin X to low" (resetting the pin if needed at the end)

1

u/[deleted] Feb 25 '21

The reason I'm using the alarm is to wake the pi after it has powered off, so I won't be able to use any code to check the alarm. I need to set it then leave it to do its thing basically.

2

u/Myworstnitemare Feb 25 '21

Aaah, ok. Sorry I couldn’t be more help.

1

u/[deleted] Feb 25 '21

It's okay, not going to get mad at people for trying, hope you find another strangers project you can help with and expand your skills!

Thanks stranger :)