Saturday, December 7, 2024

Order your Christmas presents now !!

 For an index to all my stories click this text

Now is the time !!

Just a shameless plug.

IF you have any friends, loved ones or relatives that are stepping into the wonderful world of Microcontrollers, electronics or the Internet Of Things please consider buying one of my books. And now is the time so it will arrive in time before Christmas

And by ordering these books you also support this weblog which allows me to buy new sensors etc. to build new projects and write about them.

These books are aimed at beginners to this hobby and are clearly written with many examples and projects that get you started right away.


This book was written several years ago and is still a bestseller.
It explains working with a breadboard, the C++ (Arduino) language and explains the workings of many sensors. Next to that the book shows how to work with cloud based services. It also shows how to build a simple webserver that allows to get sensor (like your home temperature etc) data from anywhere in the world.
Click here to buy this book.


The Raspberry Pi Pico was the first microcontroller from the Raspberry Pi Org. that is well known for its small Linux computers. The Pico took the IOT world by storm because of it's low price, worldwide availability, many IO pins, great speed and the availability of the MicroPython language that makes programming this chip really easy. This book shows how to install MicroPython, and covers the basic syntax of this easy to learn language. Next to that the book shows how to work with all kinds of sensors, motor, buttons etc. etc. All projects are well documented and breadboard based so no soldering !! The projects in this book will also work on the Pico2.
Click here to buy this book.


The Raspberry Pi Pico W is the successor of the Pico and adds Wifi to its capabilities. The book shows how to install the MicroPython language and the basic syntax. Then it focus on working with many sensors, motors, buttons etc. The book shows how to use wifi to get access to internet services. And a lot of attention is paid to building webservers in MicroPythoin that allow you to read sensors (like your home temperature) and set lights on or off from anywhere in the world. The projects in this book will also work on the Pico 2W
Click here to buy this book.


Javascript is without a doubt the most used computer language in the world. Anytime you click a button on a webpage or see some interactive action on a webpage Javascript is involved.
This book does not learn how to program in Javascript but gives you hundreds of tips while programming in this language. It covers topics like sorting of data, date manipulation like calculating the number of days between days, rounding figures, hding and showing hidden elements on a webpage, acting on key presses etc. etc. etc. There are hundreds of tips covering almost any aspect of building interactive webpages and working with the data on these pages.
This book might also be a valuable asset when building webservers with microcontrollers like the ESP32 and Raspberry Pi Pico series.
Click here to buy this book

Have a good Christmas
and have fun

Luc Volders

Sunday, December 1, 2024

Raspberry Pi Pico 2W with MicroPython !!

For an index to all my stories click this text

Found it !!!
With some help of Reddit readers I found MicroPython for the Raspberry Pi Pico 2W.
It is a preview version of MicroPython V1.25.0.
Strange thing is that it is available somewhere in the Pico documentation on the Raspberry Pi webpages but NOT on the official MicroPython webpage........
Lesson learned: always have a look at the manufacturers documentation.

Anyway here is it:


https://www.raspberrypi.com/documentation/microcontrollers/micropython.html#what-is-micropython

As soon as I found it I did some tests.


This test uses the requests library to get the, up to date, share price of the Raspberry Pi shares at the London stock exchange.

The program is taken from my book on the Raspberry Pi Pico which you can find at the bottom of this page. Or click the link.
The API call is different from the one in the book and is from an upcoming story on getting share prices.


This is also taken from my book on the Raspberry Pi Pico W and is a small web-server that puts a simple text on a webpage.


And here is the result.

These first tests show that MicroPython is up and running.
Ready for some new projects !!

Remember: this is the Raspberry Pi Pico 2W so it has loads of memory, storage and is a lot faster than the original Pico W.

Till next time,
have fun

Luc Volders
 

Friday, November 29, 2024

Raspberry Pi Pico 2W with Arduino IDE

For an index to all my stories click this text

This week the Raspberry Pi Pico 2 W became available.


The Pico 2 is the successor of the original Pico but now with more memory and a lot faster. You can find a description here:
http://lucstechblog.blogspot.com/2024/08/first-look-at-raspberry-pi-pico2.html

The Pico 2 W is the much anticipated version with Wifi !!!


Unfortunately at the moment of this writing MicroPython is not yet available. But The Arduino language is !!!

Installing the Raspberry Pico 2 W in the Arduino IDE is actually extremely easy.

Make sure you are using the Arduino IDE version 2 or higher.


First step is to click on the Tools drop down menu and select Board and then Boards Manager




In the Boards Manager look for raspberry.
We are especially looking for the Raspberry Pi Pico/RP2040/RP2350 entry by Earle F. Philhower III


In the drop-down menu choose the latest version. Make sure that it is at least version 4.3.0 and install this version or update your previous version by clicking on the appropriate button.
Installing will take a minute, but if things get busy it might take a bit longer as there is a lot of info that needs to get downloaded from the internet.


Now open the Tools menu again, choose the boards section and there choose Raspberry Pi Pico/RP2040/RP2350 and at the top of the list you can see the Raspberry Pi Pico 2W entry.

I did some small tests and everything seems to work like promised, including the wifi section.

Thank you for building this Earle !!!!

Those working with Kubuntu Linux (like me) can find a tutorial on how to program the Pico here:
http://lucstechblog.blogspot.com/2024/09/raspberry-pi-pico2-with-arduino-ide.html

Till next time
have fun

Luc Volders

Tuesday, November 26, 2024

Pico 2W is available

For an index to all my stories click this text

Just a quick note.


The Raspberry Pi Pico 2 W is available in the Netherlands.
It was officially released yesterday and the Dutch official Raspberry reseller Kiwi Electronics already has it in stock. Price at this moment around 8 Euro.

This is the Raspberry Pi Pico 2, which was discussed here, but now with Wifi.

Only one small problem though:
No MicroPython yet !!!
Eagerly waiting .........

Till next time,
have fun

Luc Volders

Friday, November 22, 2024

Cardboard suspension

For an index to all my stories click this text

"Nice" said my girlfriend. "That will attract some attention at our stand at the fair. But how are we going to hang it to the walls ???"

Well making some small holes in the cardboard and put a tiny wire from the back to the front, would be an option. Then we could make a knot at the front that can not pass the hole and were set.

There is only a small problem with this.
The combined weight of the letter and the small paintings in it might have the wire cut in the cardboard. And presuming we might use this more often on fairs I did not want the cardboard getting damaged. So I came up with this.



I designed it in Tinkercad and then printed it on my Creality CR20 Pro. I printed it in black so it would nicely blend in with the black paint of the letters.

It is a small rectangle with a length of 3 cm and a width of 2 cm and it is 2mm thick.
In the middle there is a cylinder of 9mm wide with in the middle a hole of 3mm. The cylinder is 7mm high.


The 9mm wide cylinder is pushed through a hole in the cardboard and the rope gets through the hole.
That way the rope does not cut into the cardboard.

The cylinder is higher than the cardboard so it sticks out a bit.
This makes sure the rope does not leans on the cardboard.



The baseplate is glued to the backside of the letters. This gives extra strength and makes sure it does not tilt.

And that is all.

You can get the design from Tinkercad if you need it and adjust it to your own needs.


And this is how the final construction was displayed at the fair.

Till next time.
Have fun


Luc Volders

Wednesday, November 20, 2024

Corners with magnets for working with cardboard

For an index to all my stories click this text.

My girlfriend is an artist: she paints. She makes miniature paintings with super realistic
landscapes. They are the size of a matchbox. As (last weekend) we had an exhibition at a large art fair we needed to have a way to display the miniature paintings. So I had an idea.



I wanted to make large builds of the letters of her name, and make compartments where she could put the paintings in. Her name is Els and the picture shows one of the letters lying on the floor in my living room. Each letter is about 70cm high. And made out of cardboard.

When all letters are ready they are going to be painted black.

The first step was to cut out the letters from the cardboard. I have a lot of really large cardboard in stock. I use it a lot as one of my hobbies is bookbinding. So making the baseplate was easy. But then I needed to make the compartments.

For making the compartments I needed to have all the parts completely rectangular. And sometimes I am a bit sloppy. So I decided to build some tools to aid me.

I used Tinkercad to draw some corners. Each corner is 5 cm at each side and 2mm thick.


Next I printed them and glued magnets on each side.
Put the magnets first on the corners and then apply hotglue., to hold them in place. I printed 12 sets. There is a magnet on each side so per set 4 magnets and for my 12 sets a total of 48 magnets. Doesn't have to look slick, just functional.


The magnets make them snap neatly together.


When gluing the structure I put them on the outside and inside so the walls are absolutely straight at 90 degrees.


And I also used them to keep the corners at 90 degrees.

When the glue is dry I can easily remove the corners and use them for the next part.

Works fantastic !!!
Keeps the angles at 90 degrees and makes sure I got a sleek design.



If you need the STL files you can get them from Tinkercad.


And here is what the end result looks with the letters lying on the floor in our home, and the first letter filled as a test. Next is a part to hang these on the wall. The weight is not a lot (it's cardboard remember) but I do not want any ropes to cut into the cardboard.

Till next time
Have fun

Luc Volders

Wednesday, November 13, 2024

Celebrating working a year with Linux

For an index to all my stories click this text.

Commercial company's need to make money. And sometimes that makes us dependent on them. Ignorance helps them enormously while a cheap solution is sometimes right around the corner if you dare to experiment. Read on.........

Last year November I was getting really annoyed with my computer.
I bought my system in 2018 (so 6 year old) and it runs Windows.
From powering up to the moment I can actually do something with it, takes several minutes. Well to put it exact: about 3-5 annoying minutes. And shutting down sometimes even took longer. That is not the worse part. Sometimes, while working,  the computer slows down so much that it is unworkable.

A lot of that is because the computer is updating Windows and several programs in the background. And at the same time my virus scanner is doing its work. All that takes time and slows everything down.
Another thing was, that Windows informed me, that I would not be able to run Windows 11 on my computer because it was too old.

So time to buy a new machine right ???

Well, I decided to try something else first. And man am I glad that I did.

Linux dual boot

As I was going to buy a new computer I first made a backup of all my data.
That would make it easy to transfer all my texts, schematic's foto's etc to my new machine.
Then I took the plunge and installed Linux on my old machine. I made it dual boot so I could always fall-back to Windows.


I installed Kubuntu. This is a special version of Ubuntu Linux with the KDE desktop. It has the most look and feel like Windows. That would make the switch easier.
And from that moment on I started working with Linux. And of course I had the safety net of a dual boot system, so I could switch back to Windows anytime.

And I never did.

I never went back to Windows !!!

All the programs I need are available under Linux. To name a few: Office (LibreOffice), the Gimp, Thonny, Fritzing, Arduino IDE, Audacity, Cura, Prusa slicer, Firefox, Chromium (a Chrome clone), Discord, VNC viewer, Kicad etc.
My Epson Ecotank ET-2814 printed immediately and it's scanner was also direct recognized and worked flawless. Same for my external harddisks, USB sticks and communication with ESP's and Raspberry Pico's over USB.

Next to that: my system starts within 2 minutes and shuts down within a few seconds. No annoying updates in the background forcing me to restart. Virus-scanner ??? No sir. Linux is a very safe operating system and there are almost no viruses around. And yes: there is a virus scanner if that makes you feel safer.

So, I did not buy a new computer and happily work with my crusty old system.
At this moment it is fast enough to be my daily workhorse but eventually it will break down due to its age. And I already have an idea on what my new computer will be.
Actually I have already discussed it this year on this weblog.........

For now:
All glory to Tux !!!


The above image is a picture of Tux. The Linux mascotte. Picture courtesy of Wikipedia.

So if you own an old computer and think about getting a new one: try Linux first. You may get pleasantly surprised.

Till next time

Luc Volders

Friday, November 8, 2024

Pico audio Part 5 - Talking clock

For an index to all my stories click this text

This is another entry in the series about producing audio with the Raspberry Pi Pico. Audio on the Pico sounds great. Not like the vintage Commodore speech synthesises. No this sounds like real audio. In this story I will show how to build a speaking clock. This story heavily leans on the previous stories so I urge you to read them first.

I like to emphasize again that this delivers a very good audio quality !!!

Audacity. This was the first story in this series. Here I showed how to record audio and save it in the required 8k wav file format. I chose audacity for this while it not only allows to record audio with a microphone but also can convert other audio files (like mp3) to the format we need. Read that story here:
http://lucstechblog.blogspot.com/2024/10/audacity-pico-audio-part-1.html

Pico audio 2. This story shows how to build the hardware needed for producing audio. Do not worry is is very cheap. The only thing you need is 6 resistors and 2 capacitors. Oh, and of course a Raspberry Pi Pico or Pico W. You can find this story here:
http://lucstechblog.blogspot.com/2024/10/audio-on-pico-part-2-hardware.html

Pico audio 3. This story deals with the software side. To produce audio on your Pico you will need no less then 5 libraries. This story shows where to get them and how to write your first program that speaks out loud "Hello World". All done in MicroPython. Read the story here:
http://lucstechblog.blogspot.com/2024/10/pico-audio-part-3.html

Pico audio 4. This story brings the first practical project: a speaking thermometer. For  building this project you will need a Dallas DS18B20 digital thermometer, next to the hardware described in the second story. The program is written in MicroPython. Read the story here:
http://lucstechblog.blogspot.com/2024/11/pico-audio-part-4-talking-thermometer.html

Getting the time.

Generally when you are working with your Pico in MicroPython you will have the Pico connected to Thonny. If you type the next commands in the shell:

import time
print(time.localtime())


The Pico will respond with something like:

(2023, 1, 25, 21, 8, 58, 2, 25)

The answer is build up like this:
year, month, day, hour, minute, seconds, weekday, yearday

The year is 2023, the month is 1 (January), the day is 25, the hour is 21, minutes is 8,seconds 58, weekday is 2 and yearday is 25. This data is stored in a tuple.

To get the hour you need to fetch the 3d element in the tuple like this:
hour = time.localtime()[3]

To get the minutes, fetch the 4th element like this:
minute = time.localtime()[4]

As you can see I was writing this story on the 25th of january 2023 at 21 hour 8 minutes and 58 seconds.
The weekday is 2. Weeks start at 0 on Sunday. So weekday 2 is tuesday. And it is the 25th day of this year.

So print(time.localtime()) gives us a load of information. Useful information with which we can make some great projects. Think Internet Of Things and actions that only need to be taken on Mondaýs for example or every 10th day.

But.........There always is a but...........

When you connect the Pico to Thonny your Pico gets the right time from your computer through Thonny. This means that if you disconnect and therefore power-down, Pico loses the right time.
So if you use the Pico stand-alone and power it from a usb power supply or battery or power-bank the Pico does not get the right time. So it starts with it's initial time and that is the unix Epoch time. The date is set to 1 January 1970 at midnight.

How to set the right time.

It is not much of a clock if it does not give you the right time.
There are 3 ways to set the right time in the Pico.

The first one is the old fashioned way to set the time manually. Add some switches to the Pico and with each press of one of the switches add 1 to the hour or add 1 to the minutes.

The second way is to use a special device called a real-time-clock. This is a clock chip with a small battery that operates for several year. I am not going to use that here.

Mind you. The Pico has a build in RTC (real time clock) but no battery back-up. So you still have to set the time each time the Pico reboots.

The third solution is to use a Pico W. The Pico W has wifi and can connect to a so called NTP-server. This is an abbreviation of Network-Time-Protocol server. You need to install a MicroPython library for this. If you want to know how to do that just look at this story:
http://lucstechblog.blogspot.com/2023/04/getting-right-time-with-micropython.html

In this version of the talking clock we are going to set the time manually by means of 2 buttons: one for the hour and one for the minutes.

With print(time.localtime()) we can get the time. However we can not set the right time this way. We need to address the internal RTC for that. Therefore the RTC library is needed and that is included in MicroPython so no need to download that.

The exact syntax for this is:

import machine
rtc = machine.RTC()


and then:

rtc.datetime((year, month, date, weekday, hour, minute, seconds, subseconds))

The value of subseconds is hardware dependent so different values on a Pico then from another microcontroller. Usually you will only set year, month, day, hour and minutes and set the remaining variables to zero. That is when setting the time manually. The NTP server or a RTC module will give the right seconds to.

Now we know how to set the right time we need to complete our speech files.

Revisit Audacity

In the first story I used Audacity to record audio files with a microphone. We recorded the words 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 30, 40, 50, "it is now", "degrees". We needed those for our talking thermometer.

Please restart Audacity and record the words "minutes", "midnight" and "hour" and add these to your Pico's Sounds directory.

The hardware setup

For building the talking clock we need the Raspberry Pi Pico (or Pico W) and the hardware for producing the audio as discussed in the second story in this series. You can find that here:
http://lucstechblog.blogspot.com/2024/10/audio-on-pico-part-2-hardware.html



For setting the clock's hour and minutes I added two buttons. And I added another button to get the time. The buttons are attached to a 10K pull-up resistor. The hour button is attached to GP18. The minutes button is attached to GP19. The button for getting the time is attached to GP20.

The talking clock program

In the Picoaudio 2 story you can find where to get the necesary libraries. It also discuses a small test program to check wether your audio setup is working correctly. Please read that story first and try the test before proceeding.

And here is the full program:

import time
import machine
from wavePlayer import wavePlayer

but01=machine.Pin(18, machine.Pin.IN)
but02=machine.Pin(19, machine.Pin.IN)
but03=machine.Pin(20, machine.Pin.IN)

player = wavePlayer()

rtc = machine.RTC()

# set your own date and time here
year = 2023  
month = 1
date = 25
hour = 17
minute = 54

rtc.datetime((year, month, date, 0, hour, minute, 00, 0))

print(time.localtime())
time.sleep(2)

while True:
        
  if (but01.value()==0):
      print("button 1 pressed")
      hour = time.localtime()[3]
      minute = time.localtime()[4]
      hour = hour + 1
      if (hour == 24):
          hour = 0
      hour2=hour

      print (hour2)
      rtc.datetime((year, month, date, 0, hour, minute, 00, 0))
      if (hour2 == 00):
        player.play("/Sounds/midnight.wav") 
      if (hour2>0 and hour2<=20):
        player.play("/Sounds/"+str(hour2)+".wav")
      if (hour2 == 24):
        player.play("/Sounds/midnight.wav")   
      if (hour2>20 and hour2<=23):
        player.play("/Sounds/"+str(20)+".wav")
        hour2 =  hour2-20
        player.play("/Sounds/"+str(hour2)+".wav")
      print(time.localtime())
      time.sleep(.5)
    
  if (but02.value()==0):
      print("button 2 pressed")
      hour = time.localtime()[3]
      minute = time.localtime()[4]
      minute = minute + 1
      if (minute == 60):
          minute = 0
      minute2=minute    
      rtc.datetime((year, month, date, 0, hour, minute, 00, 0))
      if (minute2 == 0):
        print("0 minutes")   
      if (minute2>0 and minute2<=20):
        player.play("/Sounds/"+str(minute2)+".wav")
        
      if (minute==30):
        player.play("/Sounds/"+str(30)+".wav")
      if (minute2>20 and minute2<30):
        player.play("/Sounds/"+str(20)+".wav")
        minute2 =  minute2-20
        player.play("/Sounds/"+str(minute2)+".wav")
        
      if (minute==40):
        player.play("/Sounds/"+str(40)+".wav")
      if (minute2>30 and minute2<40):
        player.play("/Sounds/"+str(30)+".wav")
        minute2 =  minute2-30
        player.play("/Sounds/"+str(minute2)+".wav")

      if (minute==50):
        player.play("/Sounds/"+str(50)+".wav")
      if (minute2>40 and minute2<50):
        player.play("/Sounds/"+str(40)+".wav")
        minute2 =  minute2-40
        player.play("/Sounds/"+str(minute2)+".wav")
 
      if (minute2>50 and minute2<60):
        player.play("/Sounds/"+str(50)+".wav")
        minute2 =  minute2-50
        player.play("/Sounds/"+str(minute2)+".wav")
      print(time.localtime())
      time.sleep(.5)
      
  if (but03.value()==0):
    print("=========================================")  
    print(time.localtime())
    print("=========================================")
    player.play("/Sounds/itsnow.wav")
    
    # get the stored hour
    hour = time.localtime()[3]
    
    if (hour == 00):
      player.play("/Sounds/midnight.wav") 
    if (hour>0 and hour<=20):
      player.play("/Sounds/"+str(hour)+".wav")
    if (hour == 24):
      player.play("/Sounds/midnight.wav")   
    if (hour>20 and hour<=23):
      player.play("/Sounds/"+str(20)+".wav")
      hour =  hour-20
      player.play("/Sounds/"+str(hour)+".wav")
    player.play("/Sounds/hour.wav")  
    
    # get the stored minutes
    minute = time.localtime()[4]

    if (minute>0 and minute<=20):
        player.play("/Sounds/"+str(minute)+".wav")
        
    if (minute==30):
        player.play("/Sounds/"+str(30)+".wav")
    if (minute>20 and minute<30):
        player.play("/Sounds/"+str(20)+".wav")
        minute =  minute-20
        player.play("/Sounds/"+str(minute)+".wav")

    if (minute==40):
        player.play("/Sounds/"+str(40)+".wav") 
    if (minute>30 and minute<40):
        player.play("/Sounds/"+str(30)+".wav")
        minute =  minute-30
        player.play("/Sounds/"+str(minute)+".wav")

    if (minute==50):
        player.play("/Sounds/"+str(50)+".wav") 
    if (minute>40 and minute<50):
        player.play("/Sounds/"+str(40)+".wav")
        minute =  minute-40
        player.play("/Sounds/"+str(minute)+".wav")
 
    if (minute>50 and minute<60):
        player.play("/Sounds/"+str(50)+".wav")
        minute =  minute-50
        player.play("/Sounds/"+str(minute)+".wav")
        
    if (minute != 0): 
        player.play("/Sounds/minutes.wav")

    time.sleep(1)

You can copy this and paste it into Thonny.

As usual on this weblog I am going to discuss some of the details in this program.

import time
import machine
from wavePlayer import wavePlayer

These are the necesaqry libraries. Time is obviously needed when building a clock.... The machine library is needed for thr RTC and the buttons. And the waveplayer library is the one that produces the audio.

but01=machine.Pin(18, machine.Pin.IN)
but02=machine.Pin(19, machine.Pin.IN)
but03=machine.Pin(20, machine.Pin.IN)

The buttons are defined and assigned to their pins. but01 on GP18 for setting the hour. but02 on GP19 for setting the minutes. And but03 on GP20 for getting the time.

player = wavePlayer()

rtc = machine.RTC()

The waveplayer library is initiated and we call it player for convenience. The RTC library is also initiated and that is called rtc.

# set your own date and time here
year = 2023  
month = 1
date = 25
hour = 17
minute = 54

rtc.datetime((year, month, date, 0, hour, minute, 00, 0))

print(time.localtime())
time.sleep(2)

If you start the program from Thonny, which you should for testing purposes, you can fill in here the current date and time. Then you do not need to set the time with the buttons. You can fill in any date you like. The RTC does not mind....... For testing purposes set the hour and minutes a bit earlier so you can test the buttons.

  if (but01.value()==0):
      print("button 1 pressed")
      hour = time.localtime()[3]
      minute = time.localtime()[4]

When the first button is pressed the program gets the hour and minutes from the rtc using time.localtime. The first time the program is run the hour and minutes are those that we put in at the beginning of the program. The second time the button is pressed the hour is already different and therefore we need to check it.

      hour = hour + 1
      if (hour == 24):
          hour = 0
      hour2=hour

Then we add 1 to the hour. Then we check if the hour is 24. If it is the clock must not say 24 hour xxx minutes. The clock starts again at 00 at 24.00 hour. So we set it to 0.
Next the value of the hour variable is copied into the hour2 variable. We will use that one to do some calculations.

      print (hour2)
      rtc.datetime((year, month, date, 0, hour, minute, 00, 0)

As a check the hour2 variable is printed in Thonny's shell. The Real Time Clock is set to the new values in this case only the hour has changed.

      if (hour2 == 00):
        player.play("/Sounds/midnight.wav") 

The program tests if the hour is 0 and then the player speaks the word "Midnight".

      if (hour2>0 and hour2<=20):
        player.play("/Sounds/"+str(hour2)+".wav")

If it is between 0 and 21 hour the player speaks out one of the 20 wav files in the Sounds library. The hour2 value is an integer value so we translate it first to a string and then add ".wav"
This way the hour 10 becomes "10.wav"

      if (hour2>20 and hour2<=23):
        player.play("/Sounds/"+str(20)+".wav")
        hour2 =  hour2-20
        player.play("/Sounds/"+str(hour2)+".wav")

If the hour is between 20 and 24 the player speaks out the file "20.wav" next 20 is subtracted from the hours value and the remaining figure is spoken.

This is code is basically the same for but02. Only here we test for the minutes and the test is a bit more extensive as the minutes go up to 59.

And for but03 the code is basically also the same. The difference is that this button is only used for having the clock speaking the time and no values are altered.

Using the clock

First you need to decide whether you want this clock program to start up immediately after the Pico is powered up. If so you need to save this program using the name main.py MicroPython automatically runs a program with the name main.py at powering up.

I advise however to first test this program running from Thonny. Then you can intervene if something is not working. So first save it as for example Talkclock.py

When powering the Pico from a power bank (and the program is started as main.py) the clock will not have the actual time. So press the hour button and each time you do the hours are raised by one and you will hear the clock saying the hour in your own voice. Same goes for setting the minutes with the second button.

When the time is set no further action is needed. Just press the third button when you want to know the time.


Here is my breadboard setup. The Pico on the right side with a label lying on top of it showing the pin numbers. You can find that here: http://lucstechblog.blogspot.com/2021/03/raspberry-pico-pin-layout-help.html The audio hardware is still on a separate breadboard as I use it on several Pico's.  The audio output is connected with crocodile clips to an active speaker. And yes: on the left side on the bottom is an SD card. 

Expansions

The clock speaks the time in hours and minutes. So at 13.45 it wil say "It is now 13 hour 45 minutes" At 10.30 the clock says "It is now 10 hour, 30 minutes"
This is not exactly like how we look at a clock in real life. Normally we say it is quarter to one or half past 10 etc. The problem is that we run out of memory on the Pico. There is not a lot room left to add more voice recordings. Luckily there is a solution. We can attach an SD card to the Pico and then we get virtually unlimited memory. That story is coming up.

If you are using the Pico W instead of the ordinary Pico you can connect the Pico to the internet to get the exact time from a Network Time Protocol server. You can put that time into the RTC and you always will have the right time.

Another expansion would be to attach the DS18B20 to the Pico like we did in the third story. Add another button and presto we have the time and temperature at hand.

Another thing that comes to my mind is incorporating an alarm. You can record the sound of an alarm bell or have your spouse/partner speak a wake-up call. For this we would also need more memory for the voice/audio recordings.

But for now this works great !!
And it really is a fun project.

Till next time.
Have fun


Luc Volders