Showing posts with label ESP-01. Show all posts
Showing posts with label ESP-01. Show all posts

Friday, March 28, 2025

Print your own USB connector

For an index to all my stories click this text.

Sometimes I find something on the web that is so usefull that I want to share it with you.

Powering your circuits.

When testing and building a small circuit with just one or two sensors you can use the power that your microcontroller supplies over it's 5V pin. Both the ESP32 and the Raspberry Pi Pico have a 5V and 3V3 power out pin.

But when I need more power I use an USB breadboard connector to power the project.


An example is this circuit where two TM1637 7 segment displays are connected to a Raspberry Pi Pico. The Raspberry pi pico is powered through it's USB port and on the left-top side you can see a breadboard USB connector attached to a USB power plug.

Nothing wrong with this but I always seem to run out of breadboard USB connectors.

3D printer to the rescue

Then I found this on the web:
https://www.instructables.com/Minimalist-USB-Connector-No-Special-Hardware-Requi/


This is a 3D printed USB connector. The photo shows the assembled version.
But does it work ????


Works like a charm !!!
As you can see the USB connector is plugged into a powerbank and the multimeter shows that a nice 5V is supplied.

The STL files

The connector consists of 2 parts.

You can find the STL files in the original story which you can find here:
https://www.instructables.com/Minimalist-USB-Connector-No-Special-Hardware-Requi/


The first part is the bottom in which you need to insert the wires. The second part is the top which you should glue and press on to the bottom part when the wires are placed. The top part has ridges that help keep the wires in place.


This is how the files look in my slicer. I use Cura.


Set the quality at 0.2mm and supports on. As these are small parts you could set adhesion also on.

Assembling

I used solid copper wire with a diameter of 0.5mm. That worked very well.

I took a slightly different approach to assembling as what the original developer described.

First I stripped the wires.


Then I pulled the stripped part through the holes.

Then I glued the lid on.
The last step was to cut off the excess wire.

The blue wire at the top is GND.
The red wire at the bottom is VCC (5V).
Please test before you actually put it to use to make sure the wires are not twisted. If you mix the wires up you might/will blow up your circuit so test, test, test !!!


The wires are thick enough to fit direct into a breadboard.

You can make the wires any length you want. Short to connect to a powerbank and fit on your desk. Or make them long to connect to a wall outlet with an USB power plug.

I have printed several of these. They are ready to use in my drawer. A really great design.

Til next time
Have fun

Luc Volders

Friday, March 14, 2025

Speeding up Domoticz

For an index to all my stories click this text.

As you might know from previous stories on this weblog I have Domoticz installed as my home automation system. It was only getting slower and slower.

Now my idea was that the problem might lay in the fact that I was using a Raspberry Pi 2. And as I installed the latest updates, that could indeed slow down my system. So I considered upgrading to a Pi 3 or Pi 4.
And just for your information: If you want to install Domoticz you will need at least a Pi3 as previous versions are no longer able to install Domoticz.



Clicking on the Devices Tab in the settings menu stopped the complete system for several minutes.

Then I noticed something.



Each page of the devices pages contains 100 entries (you can select that). And I had no less then 225 pages. That means that the database had 22500 entries.



And many of these entries were from years ago. As you can see the highest page numbers pointed to database entries from 2016. That is 7 year ago, at the time of this writing !!!

Why on earth would I want to keep that information. More even while the entries hold info on switches, thermometers etc from neighbours. And that that does not interest me.



So at the top of the page I clicked on the button that says Ongebruikt. The English version will mention Unused.

Next I clicked on the small V at the top. After two clicks all entries on that page were selected. Then I clicked on the waste basket next to the V and the entries from that page disappeared.

Make sure you use the Unused entries button otherwise you might remove your own settings !!!!

I removed all unused entries that way and this made Domoticz fast again !!!
So no need to switch to a more modern Raspberry Pi or even another home automation system !!!

Please be aware that Domotics keeps receiving and storing data from all kinds of switches and thermometers all the time. So a regular cleanup is advised.

Maybe it's me, but I could not find this simple speed improvement in the manual, so I did not want to keep it from you.

Till next time
have fun


Luc Volders





Friday, September 13, 2024

Testing an obstacle avoidance sensor

For an index to all my stories click this text

I was playing around with an obstacle avoiding sensor and want to share my experiences with you.

What is it.

An obstacle avoidance sensor is mostly used in robotics.

The sensor has an infrared led. This led sends out lightin the infrared spectrum which we can not see. the light normally shines streight on.

Next to the infrared led there is a photodiode. That photodiode detects infrared licht.

When the sensor approaches an obstacle the infrared light is reflected back and detected by the photodiode.

Like said, this is mostly used in robotics. The sensor is mounted on a robot and when the robot comes close to a wall or any other obstacle the photodiode sends a signal to the robots controller to alter direction.

The sensor

This is how the sensor looks in real life. Let's have a look at the different parts of it.

On the left you can see the photodiode at the top and the IR led beneath it. They are next to eachother so the there is a maximum chance of detecting any reflection.

In the middle there is a screw with witch you can adjust sensitivity. That means by turning the screw you can adjust the maximum distance at what the reflection is detected.

Next to the header pins there are two leds. The top led is the power led and that is always on whenever the sensor has power. The led at the bottom is off and goes on when an obstacle is detected.

A test setup

To test the sensor I build a simple setup on a breadboard. I connected the sensor to a Raspberry Pi Pico. Here is what the breadboard looks.


The led (I used a blue one) is connected with a current limiting resistor to GND and to GPIO15.

Pico's GND (pin38) is connected to the sensor's GND. and Pico's 5V (pin 40) is connected to VCC. The sensors output (OUT) is connected to GPIO16.

Test program in MicroPython

To test the sensor I wrote a simple program in MicroPython.

import time
from machine import Pin

obstac = Pin(16, Pin.IN)
led = Pin(15, Pin.OUT)

while True:
      print(obstac.value())
      led.value(not obstac.value())
      #led.value(0)
      time.sleep(.2)

In the loop the program constant tests the out pin of the sensor. When that pin's output changes from 1 to 0 (obstacle detected) the led on GPIO15 goes on.

Copy this program, paste it in Thonny and save it as main.py on your Pico. It will work on the Pico, Pico W and Pico2.
Saving it as main.py makes the program run immediately when the Pico is powered up so you can do some tests with a powerbank, phone charger or batteries.

If you want to learn about MicroPython on the Raspberry Pi Pico or Pico W please consider buying one of my books that are listed at the bottom of this page.

First test.

This should immediately work. Just hold your hand above the sensor and move it towards the sensor. At a certain moment the led will go on both on the sensor as well as the blue led.

Now you can adjust the screw in such a way that the leds will go on at your desired distance.

Distance

According to some specifications I found you can adjust the screw so the distance at which the led will go on can be set from 2 to 20 cm.

Just be aware that there are environmental issues that might influence the detection distance. Here are some things you might like to take into consideration.
- Temperature may affect the distance
- TL light might affect the distance
- Sun light might affect the distance
- Direct light shining on the photodiode might affect the distance

The only thing I want to say is that you should adjust the sensivity screw in your real-life setup.

Some tests

Here are the results of some tests I performed.


All leds are OFF because there is no obstacle in front of the sensor.


A shining transparant box was put in front of the sensor and at a distance of 8 cm the obstacle was detected.


A black piece of paper was put in front of the sensor and at 6cm it was still not detected.


The black paper was detected at 2.5 cm.
This means that the black paper absorbed (did not reflect) a lot of infrared light so it was not detected until it was at a short distance.


A white piece of printer paper was detected at 8 cm distance. The white color reflects the infrared light more so the paper was earlier detected.


A black shining object was detected at 4cm. This means that the black color absorbed some infrared light but the shing surface reflected also some infrared light.


A book (yes my book about the Pico) with a shining green cover reflected the infrared light at a larger distance so it was already detected at about 8.5cm

Water ???

Solid obstacles: OK
But how about fluids.

If you want to reproduce this test yourself just make sure the electronics don't get wet. Water and electronics don't mix and you might damage your sensor or pico beyond repair.


I filled a white bowl with a small layer of water and help the breadboard above it.
The led stayed off: no obstacle detected.


I used a bottle of water to gradually fill the bowl and yes !!!
At a certain moment the led went on. So water reflects the infrared light.


Concluding

First let me state that obstacles are detected very well.
In the demo program you can lower the delay and that will not affect the working of the sensor. So in real life you should use an interrupt for testing for an obstacle which is the fasted method.

The obstacle avoidance sensor detects obstacles but does not give any indication at what distance the obstacle is 'seen'. The difficulty lies in different materials reflecting the infrared light more or less.
If you need to measure distance then use an HC-SR04 ultrasonic sensor.

This means that you should adjsut the sensivity screw so that the obstacle is detected at a larger distance when you are working with a fast moving object like a remote controlled car. That is because you will need time to shut the motor down. But you also need to take the obstacles material in count as black obstacles are seen later.

I was specially impressed when I realised that the sensor also detected water as an obstacle.
I did not try but wonder if a black bowl would make a difference.

And remeber: you can always use this sensor inverted. Meaning that an alarm is given when an obstacle is removed like the lid of a box is taken off.

Till next time
Have fun

Luc Volders




Friday, July 12, 2024

Install Linux programs with Appimage

For an index to all my stories click this text.

As you might know I switched from using Windows on my desktop machine to Ubuntu. And to be more specific to Kubuntu. Kubuntu has the Windows look and feel but still is full Linux with all it's benefits: loads of software freely available, easy to use, great security so no need for a virus killer, great file system so no need for disk defragmentation etc. etc. etc. This all leads to an enormous speed improvement on the same computer that was running windows.

At first I was a bit sceptical. I did not know if all the software I needed was available. So what I did is I installed Kubuntu on a USB stick and run it from that stick. That way my Windows drive was intact and I could switch anytime I like back to Windows.
Well after working 2 months from a USB stick and never turning back to Windows I was convinced and installed Kubuntu permanently on my harddisk.

Installing software


Installing software in Kubutu is easy. Kubuntu includes a program that is called Discover. Starting that program will show you a list with all available software. Clicking on a title installs that package for you. Easy: no difficult Linux commands to learn.

Everything you need is there: Office, Thonny, audio playes, video players, terminal programs (for ssh into raspberry pi's), Cirkit and Fritzing for schematics, web-browsers, mail programs, Cura and Prusa slicer (for your 3D printer, the Gimp, text editors, Discord etc. etc. etc. All the packages look great and they have that Windows look and feel so no steep learning curves.

Arduino ide

I only had a small problem with the Arduino IDE.



The Arduino IDE is available.

However there is an issue with it.




The version that is available is Arduino 1.8.19
Nothing wrong with that although version 2 is already for some time available.

But what is worse is that Kubuntu incorporates a lower version of Python than the Arduino IDE needs........
That would not bother me so much if it would work with all the Microcontrollers I work with. The Arduino IDE would work with the ESP32 and the Raspberry Pi Pico series but it does not work with the ESP8266 and that is a bummer.

Fortunately there is a solution !!!


Appimage to the rescue

There is a new way to install software packages on Linux. It is called Appimage.
Basically you download an Appimage for a software package and it contains all necessities for many Linus distributions.

AppImages are self-contained apps which can simply be downloaded & run on any Linux distribution.

This is a quote from their website.


So you can just download an Appimage, move it to a directory where you want it, click on it and it runs. And it should run on many different Linux distributions like Ubuntu, Kubuntu, Debian, Mint, Fedora, OpenSuse etc.etc.etc.

Appimagehub

There are universal software packages for all Linux distributions. But where to find the available packages.



Luckily there is Appimagehub.
Here is the link:  https://www.appimagehub.com/browse

On this website there are (at the moment of this writing) 1380 program packages available.


And look what I found in the programming section !!


Clicking on the icon revealed this screen.

Scroll down and there is a download button. Click that button.


A pop-up window appears and after a few seconds you can click the download button.
The file will get downloaded into your download folder.

I created a new directory in my Home folder and moved the file into that directory.



Click on the icon with your right mouse button and change the files attributes to Is executable.


If you now click the icon a pop-up window appears asking if you want to execute the program.
Just click Execute.


And there is the Arduino IDE 2.2.1
As you can see I installed the ESP32, ESP8266 and Raspberry Pi Pico boards and the ESP8266 programs now compile without a problem.

Appimage pro's and cons

This is a great tool but there are some pro's and cons you should be aware off.

The pro's

- Appimage's should work on any computer running Linux.
- Any user can install a program packed as an Appimage. No need to get root privileges or using the terminal with sudo to install software.
- Everything needed to install and run a program is contained in the appimage of that program. So no need to install extra programs or libraries.
- Appimages do not alter your system libraries or congiguration. So it will not cause problems with other programs.

The biggest benefit is of course that appimages run on any Linux distribution.

The con's

- The standard program installation methods like Discover on Ubuntu (Kubuntu) regularly check if there are new updates for your programs. Appimage does not do that. So you will have to check for updates yourself regularly.
- Not all programs or applications are available as an Appimage
- The installed Appimages are not shown in your Application Launcher or program menu. You have to keep track yourself where they are stored.

Removing an Appimage

If you need to remove an Appimage because you do not need the program anymore or want to download an update just find the Appimage in your directory and delete the file. That's all.

Till next time.
Have fun


Luc Volders








Friday, February 2, 2024

ESPEAsy part 5: ESPEasy to Telegram

For an index to all my stories click this text

After my previous stories on ESPEasy I received a few mails from readers that wanted to know if it is possible to send data direct from ESPEasy to Telegram. The advantage in that is that you can send alarm notifications direct to your phone.

If you do not know what ESPEasy is I urge to at least read my introduction tutorial and the tutorial about communication between two ESP's with ESPEasy. You will be amazed about the amount of features and drivers for sensors are crammed in this alternative operating system for the ESP8266 and ESP32. You can find these stories here:
http://lucstechblog.blogspot.com/2023/10/espeasy-part-1-iot-without-programming.html

http://lucstechblog.blogspot.com/2023/12/espeasy-part2-send-data-from-esp-to-esp.html

I also did a story on how to send data from ESPEasy to WhatsApp.
http://lucstechblog.blogspot.com/2024/01/espeasy-part-4-espeasy-send-data-to.html

Some readers pointed out to me that sending data from ESPEasy to Telegram should be easier as Telegram can communicate through a Bot. Well actually that is true and also not true.
Indeed Telegram can communicate through a Bot however that communication is done over HTTPS (secure HTTP) and ESPEasy does not (yet ???) support HTTPS.
The ESPEasy developers have stated that HTTPS communication requires a lot of memory and memory is scarce in ESPEasy as it is already crammed with features.

So as HTTPS communication is (as for now) out of the question rests just one other option at this moment and that is sending data to Telegram using the CallMeBot service.

CallMeBot

CallMeBot is a free service that is especially created to have electronic devices like the ESP8266 and ESP32 or programs send messages to WhatsApp, Telegram, Signal and Facebook. You can find it's website here: https://www.callmebot.com

We have to use the CallMeBot API to send messages from ESPEasy to CallMeBot. In a previous story I showed how to send data from an ESP8266 to WhatsApp and that explained how this works. Please re-read this story before you go on. You can re-read it here: http://lucstechblog.blogspot.com/2021/05/esp8266-and-esp32-sending-messages-to.html

That story showed that to send a message to WhatsApp through CallMeBot we have to use the following format:
http://api.callmebot.com/whatsapp.php?phone=+XXXXXXXXXXXX&text=This+is+a+test&apikey=YYYYYY

For Telegram there is a similar command:

https://api.callmebot.com/text.php?user=@myusername&text=This+is+a+test+from+CallMeBot

You can see the difference. CallMeBot does not sends the message to a Phone number but to your username. So start with setting your username in Telegram if you have not done so yet.



On your phone in the main Telegram menu click the hamburger icon at the top left of your screen. And then click General Settings.



Look at your profile settings and give yourself a username. Choose it carefully as all your contacts can use this username to send messages to you.

When done open your webbrowser to the CallMeBot webpage: https://www.callmebot.com/



Choose in the drop down menu Send Text Messages.



On this page you will find the explanation on how to use this service. And you can see the api call you need to use to send data to Telegram. As shown before in this text the api call looks like this:

https://api.callmebot.com/text.php?user=@myusername&text=This+is+a+test+from+CallMeBot

There is a green button on the page that says "Try to Send a test message now!" Click that button.



Fill in your username and your Text Message to Send and at the bottom you can see what URL you need to use to send the message.


Before the message is send a new screen opens which asks for a confirmation and Authentication. Press the green button and the message will be send to Telegram on your phone.



A confirmation message will be send to your phone. The above message is in Dutch as my phone is set into Dutch.



Now lets try a test message. Send the text First test.



And if all went well the message will appear in Telegram on your phone.

Breadboard


For this simple test we will only use a switch connected to D5 on our Wemos D1 Mini.

ESPEasy device setup.

I Will not go into all the details about installing the software on your ESP8266. That has been covered before on this weblog. Please re-read the stories in the following links for that:
http://lucstechblog.blogspot.com/2023/10/espeasy-part-1-iot-without-programming.html

To use the button on the breadboard got to the devices tab. Press Add and choose an input switch as the device. This also has been covered in the pre-mentioned stories. So re-read those for the details.



First let's have a look at the upper part of the devices screen.

The switch is called sw1 and it is enabled. We use the internal pull-up resistor of the Wemos D1 so check this button. The button on the breadboard has been attached to D5 which is GP14. The type is a switch and it is active when pressed so Push Button Active Low.



At the bottom make sure that Send to Controller 1 is checked and rename the variable (Values) to sw1val

ESPEasy Controller setup

The controller is a software driver that actually sends the data to another device or webservice. This is explained in the before mentioned previous stories so please re-read those for detailed information.

So switch over to the Controller Tab and Add a new Controller. As we are going to send over HTTP choose Generic HTTP as the protocol.



To locate the controller we do not use the IP adress but Use Hostname. And the Controller Hostname is api.callmebot.com
As we are sending data over HTTP the port number is 80.

We are sending data and commands to a service outside our own network so it might take a second or two to get a confirmation or acknowledgement. Therefore set the Client Timeout to 1000 ms (1 second)

The only thing left to do is to set the text we are going to publish. We have seen that the general command is:
https://api.callmebot.com/text.php?user=@myusername&text=This+is+a+test+from+CallMeBot
The hostname already has been set so we need to edit the text:
text.php?user=@myusername&text=This+is+a+test+from+CallMeBot

Replace user=@myusername with the username you have chosen for yourself.

The text we are going to send is  an indication of what the data is and the data itself. The indication is simply button= and the data from the button is found in sw1#sw1val.
So the complete call will be:

text.php?user=@myusername&text=button+=+[sw1#sw1val]

Make sure to have enabled checked otherwise the Controller is not activated and then chose Submit.

Done !!!

Press the button attached to the ESP8266 and



There you are. We just send some messages to Telegram from ESPEasy.

You can have multiple data in one command and put each of them on a new line using %0A. Here is an example that would send the data from two buttons:

text.php?user=@myusername&text=button+=+[sw1#sw1val]+%0A+button2+=+[sw2#sw2val]



And here is the result.

That's it for now. Till next time
Have fun.

Luc Volders