[Solved] Connect PICO with DS1302

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
Patriboom
Posts: 7
Joined: Tue Feb 08, 2022 5:20 am

[Solved] Connect PICO with DS1302

Post by Patriboom » Tue Feb 08, 2022 5:32 am

Hello everyone,

I've found only one source to connect DS1302 and it is with a Microbit microcontroller.
( https://github.com/shaoziyang/microbit- ... isc/DS1302 )

I now try to built the corresponding repository for PICO
( https://github.com/Patriboom/DS1302_Python_RaspPICO )

I've never touch a Microbit MC, but according to the pinout I found ( https://www.microbit-spy.co.uk/wp-conte ... pinout.png )

The pinning goes as the folling:

Microbit Description PICO PIN

clk=pin13, SPI-1.SCK 14:SPI-1.SCK 10
dio=pin14, SPI-1.MIS0 15:SPI-1.TX 11
cs=pin15 SPI-1.MOSI 16:SPI-1.RX 12

Trying to reproduce the same logical, I did the following pinout on Rasp PICO

DS1302 PICO
VCC 39: VSYS
GND 38: GND
CLK 14: SPI1.SCK -- GP 10
DIO 15: SPI1.TX -- GP 11
CS 16:SPI1.RX -- GP 12

It didn't work.
I thought to have connected Rx and Tx on reverse then I connected as:
DS1302 PICO
VCC 39: VSYS
GND 38: GND
CLK 14: SPI1.SCK -- GP 10
DIO 15: SPI1.RX -- GP 12
CS 16:SPI1.TX -- GP 11

No better chance.

Always such error message:

Code: Select all

Traceback (most recent call last):
File "", line 20, in
File "DS1302.py", line 99, in Hour
File "DS1302.py", line 62, in getReg
File "DS1302.py", line 53, in read_byte
TypeError: unsupported types for lshift: 'Pin', 'int'`
Any help will be very appreciate

Thanks
Last edited by Patriboom on Tue Feb 08, 2022 9:24 pm, edited 1 time in total.

User avatar
scruss
Posts: 360
Joined: Sat Aug 12, 2017 2:27 pm
Location: Toronto, Canada
Contact:

Re: Connect PICO with DS1302

Post by scruss » Tue Feb 08, 2022 4:46 pm


Patriboom
Posts: 7
Joined: Tue Feb 08, 2022 5:20 am

[Solved] Re: Connect PICO with DS1302

Post by Patriboom » Tue Feb 08, 2022 7:31 pm

Nice!
Thanks,

I've never found it !

Patriboom
Posts: 7
Joined: Tue Feb 08, 2022 5:20 am

Re: Connect PICO with DS1302

Post by Patriboom » Tue Feb 08, 2022 7:58 pm

Looks very good.

But, still .. I have no communication.

My pinout is:

DS1302 -> PICO
CLK -> 14: SPI-1.SCK
DAT -> 15: SPI-1.TX
RST -> 16: SPI-1.RX

I also tried
DS1302 PICO
CLK -> 14: SPI-1.SCK
DAT -> 16: SPI-1.RX
RST -> 15: SPI-1.TX


The code goes like:

Code: Select all

from machine import Pin
import ds1302

ds = ds1302.DS1302(Pin(14),Pin(15),Pin(16))

ds.date_time([2022, 2, 8, 3, 14, 23, 1, 0]) # set datetime.

hre = ds.date_time() # returns the current datetime.
print(hre)
print(ds.hour()) # returns hour.
print(ds.second()) # set second to 10.
Have I to set the pins like this:

Code: Select all

ds = ds1302.DS1302(Pin(13),Pin(14),Pin(15))

The result is always:
%Run -c $EDITOR_CONTENT
[2165, 165, 165, 165, 165, 165, 45]
165
45
Note: that is the same result as if I plugged nothing at all.


Thanks again.

Patriboom
Posts: 7
Joined: Tue Feb 08, 2022 5:20 am

[Solved] Re: Connect PICO with DS1302

Post by Patriboom » Tue Feb 08, 2022 9:23 pm

It works now!

Same pinout as above:

DS1302 ---> PICO
GND ---> GND
VCC ---> VSYS
CLK ---> 14.GP_10; SPI-1SCK
DAT ---> 15.GP_11; SPI-1TX
CS ---> 16.GP_12: SPI-1RX

with the following code

Code: Select all

from machine import Pin
import ds1302

ds = ds1302.DS1302(Pin(10),Pin(11),Pin(12))

ds.date_time([2022, 2, 8, 3, 14, 23, 1, 0]) # set datetime.

hre = ds.date_time() # returns the current datetime.
print(hre)
print(ds.hour()) # returns hour.
print(ds.second()) # set second to 10.

Post Reply