Reading from and writing to registers on an I2C device #1059
Unanswered
RickSeiden
asked this question in
Q&A
Replies: 1 comment
-
Hello again. I decided to do a little more testing, so I commented out the lines for Wire.setSDA and Wire.SCL in the first sketch and sent it to a clone of an Arduino Uno. It worked. So I did the same for the second sketch, and again it worked. Finally, I commented out the Wire.SDA and Wire.SCL lines in the class and uploaded the library version to the Uno clone, and it worked. So the native Wire library that uses the same code with the exception of Wire.setSDA and Wire.setSCL works on an Uno clone, but the Wire library for the Pico W does not work in the Class. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I am attempting to write data to an i2c device and then read it back using Wire.h. I don't think it's device specific, but it's a DS1337C real time clock with an internal crystal. (I'm running an external RTC because I need two alarms and as far as I know the PICO's RTC only provides 1.) I have it wired with RTC SDA to PICO 8 and RTC SCL to PICO 9 with 1k resistors pulling both lines up to 3V3.
I start out with a fairly simple sketch
and everything works as I expect it to.
So now I want to reduce redundancy, so I throw the read and write code into some subroutines, giving this seconds sketch:
Both of these give the same output:
So far so good, but I'd really like this to be in a library, so I write a library. First is the header file:
Next is the CPP file:
And finally is the sketch:
As you can see, I've pretty much just moved the subroutines into the Class. The problem I have is that this gives the following output:
I have no idea why this isn't working in the class. I'm hoping that someone here can help me out, but I'm not sure if this is PICO specific or not.
Thanks
PS: Why don't I just use some of the pre-written libraries for the DS1307 which has the same registers and works the same way as the DS1337C? Because the libraries I've found don't address all of the features I want, and don't return the time and date in the way that I need. Some of them, for example, don't have a way of checking that an alarm has gone off. Others return the date and time in a format I don't want to use. I could write a wrapper around them, I suppose, but I'm trying to treat this as a learning experience rather than a means to an end.
Beta Was this translation helpful? Give feedback.
All reactions