Quantcast
Channel: lucstechblog
Viewing all 318 articles
Browse latest View live

ESP32 uitgelegd nu verkrijgbaar

$
0
0
You can find an index to all my articles by clicking this text

I have been very busy last months. Not only do I have a full time job, train for an upcoming sports event (four day marches) and a 'pilgrimage' to Santiago de Compostela (a 200 mile walk), I also have spend a lot of time working with the ESP32.

This resulted in a book (my second). It is called ESP32 uitgelegd which means ESP32 explained. It is in Dutch and the English version will get a different title and is what I am working on now.

So sorry guys. The rest of this post is in Dutch.

ESP32 uitgelegd.



De trouwe volgers van dit weblog weten dat ik niet veel aandacht heb besteed aan de ESP32. Slechts een paar web-logs gaan over deze wonder-chip. Dat wil niet zeggen dat ik er niet intensief mee bezig ben geweest. Maanden uitzoekwerk, opzetten van breadboard projecten en het programmeren van voorbeelden heeft geleid tot het boek met de titel: ESP32 uitgelegd.

Het is een beginners boek. En natuurlijk volledig in het Nederlands !!
In tegenstelling tot veel van mijn verhalen op mijn weblog zijn alle programma's en voorbeelden in C++ (Arduino taal) geschreven.
Het boek begint met het installeren van de Arduino software. Dan volgen het installeren van de ESP32 componenten voor Arduino, het installeren van libraries en een korte inleiding tot programmeren.
Daarna volgen hoofdstukken die je leren met allerlei sensoren en weergevers (actuators) te werken. De schema's zijn allemaal op een breadboard uitgevoerd en in de praktijk getest waarna ze in Fritzing zijn getekend voor weergave in het boek.
Het boek is geen leerboek maar om praktijkervaring op te doen eindigd elk hoofdstuk met de beschrijving van een oefening die je zelf kunt doen met de opgedane kennis uit dat hoofdstuk.

Uiteraard ontbreekt het sturen van sensoren via een zelfgebouwde website niet. De ESP32 heeft immers niet voor niets Wifi. Maar ook Thingspeak en IFTTT komen aan bod zodat je de opgedane kennis makkelijk kunt gebruiken bij het werken in de 'cloud'.

Het laatste hoofdstuk geeft je ongeveer 30 ideetjes voor het zelf bouwen van projecten die je zeker kunt verwezenlijken met behulp van alle voorbeelden in het boek.
Het is dus een echt praktijkboek.

Je hoeft de volgorde van het boek niet aan te houden. Als je na hoofdstuk 8 denkt "ik wil met sensor zus of zo aan de slag" dan ga je gewoon naar dat hoofdstuk toe. Het kan zijn dat je dan wat achtergrond info mist, maar die kun je dan weer makkelijk terugvinden door de verwijzingen naar de betreffende hoofdstukken te volgen.

Om de prijs zo gunstig mogelijk te houden, zodat het voor jong en oud bereikbaar is, zijn alle afbeeldingen in zwart-wit. Daardoor kan het boek voor de lage prijs van 19,95 verkocht worden en is het toch maar liefst 368 pagina's dik !!!

Het boek geeft je ook een lijst van Nederlandse elektronica leveranciers zodat je niet 3 weken of meer hoeft te wachten op onderdelen uit verre landen.

Een aantal van de sensoren en technieken worden ook op dit weblog besproken maar er zijn duidelijke verschillen. In de eerste plaats zijn niet alle ESP8266 libraries geschikt voor de ESP32. En op mijn weblog zijn veel programma's in ESPBasic uitgevoerd terwijl in dit boek alle programma's in de meer universele C++ taal zijn uitgevoerd. Dat komt omdat mijn weblog vaak een specifiek probleem aanpakt terwijl het boek in meer algemene termen spreekt waardoor je de beschrijvingen breder kunt inzetten.

Mijn vorige boek schreef ik bijna 25 jaar geleden en daar werden er 20.000 (ja twintig duizend) van verkoht: https://www.boekenwebsite.nl/computers-software/praktijkboek-voor-de-commodore-64

Eens kijken of jullie dat aantal voorbij gaan.......;)

ESP32 Uitgelegd is te koop (of te bestellen) bij alle fysieke boekhandels en alle online boekhandels zoals:

Boekenbestellen 

Donner
Libris boekhandels

Bruna
Bookaroo
Athenaum Boekhandel
bol.com


Er zijn 33 hoofdstukken:

Hoofdstuk 1
Voor wie is dit boek bedoeld
Introductie
Over de auteur

Hoofdstuk 2
Het Installeren van de Arduino IDE
Installeren van het ESP32
Het gebruik van de IDE

Hoofdstuk 3
Het installeren van libraries
Installeren door middel van de library manager
Installeren van ZIP libraries
Handmatig installeren van Libraries
Eerste gebruik van libraries

Hoofdstuk 4
ESP32 Pin aansluitingen

Hoofdstuk 5
ESP op een breadboard

Hoofdstuk 6
Korte inleiding voor het werken met een breadbord

Hoofdstuk 7
Voeding
USB breadboard connector
Batterij voeding
Externe voeding

Hoofdstuk 8
Basiskennis programmeren

Hoofdstuk 9
De druktoets

Hoofdstuk 10
De Led 

Oefening

Hoofdstuk 11
Dimmen van leds met PWM.
Oefening

Hoofdstuk 12
Dallas DS18B20 digitale thermometer
Installeren van libraries
Opzetten van de hardware
De eerste test
Temperatuur alarm
Oefening

Hoofdstuk 13
LDR voor het meten van licht
Test programma
Een praktisch voorbeeld
Oefening

Hoofdstuk 14
Potmeter
Hoe sluit je een potmeter aan
Potmeter test programma
We maken een dimmer

Hoofdstuk 15
Servo Motor
Breadboard met servo
De eerste servo test
Servo met een potmeter
Servo met druktoetsen
Oefening

Hoofdstuk 16
Informatie op een webpagina weergeven
Achtergrond informatie over webpagina's
De webpagina
Breadboard opbouw
Je eerste webserver
Buttons op je webpagina
CSS voor het opsmukken van depagina
Oefeningen

Hoofdstuk 17
Meer Kracht
Het programma

Hoofdstuk 18
Krachtstroom met een relais
Relais aan en uitschakelen
Nachtlampje
Oefening
Werken met 230Volt

Hoofdstuk 19
Touch Sensor
Gebruik van de Touch pinnen
Een aanraakgevoelige lamp
Oefening

Hoofdstuk 20
Stuur een motor aan
Geef je planten water als het nodig is
Oefening

Hoofdstuk 21
IFTTT
Aanmelden bij IFTTT
Stap een: zoek de sleutel
Stap twee: zet notifications aan op je telefoon
Stap drie: de ESP32 kant
Oefening

Hoofdstuk 22
Neopixels
Hardware eisen
De eerste test
Neopixel kleuren
Thermometer met led indicatie
Gooi de dobbelsteen 

Oefening

Hoofdstuk 23
Gebruik een H-brug  voor het aansturen van een motor
Elektronische oplossing
Breadboard opstelling
Het H-Brug programma
Sneller en langzamer
Meer power
Oefening

Hoofdstuk 24
PIR bewegingsmelder
Het programma
Hoe te gebruiken 

Oefening

Hoofdstuk 25
Beweging detecteren met de RCWL-0516 Radar
Programma voor bewegingsdetectie met de radar
De RCWL-0516 in gebruik nemen
Oefening

Hoofdstuk 26
Beweging met een tril sensor
De Software
Oefeningen

Hoofdstuk 27
Tilt Sensor
Oefening

Hoofdstuk 28
Interrupts
Interrupt programma

Hoofdstuk 29
Laat je gegevens zien
TM1637
TM1637 aansluiten op een breadboard
Aansturen van de TM1637
Het programma
Oefening voor TM1637

Hoofdstuk 30
Oled Display
Breadboard Library
Programmeren van de SSD1306
De Oled library commando's

Hoofdstuk 31
Thingspeak: zet je gegevens in de Cloud
Wat is een Cloud gebaseerd IOT platform
Thingspeak
Thermometer gegevens naar Thingspeak sturen
Het programma
Extra Thingspeak mogelijkheden
Privacy

Hoofdstuk 32
Ideeën

Hoofdstuk 33
Waar vind je onderdelen

Hoofdstuk 34
Waar vind je meer informatie

Hoofdstuk 35 
Zelf aan de slag


Veel leesplezier
en tot de volgende keer

Luc Volders

Fritzing merger of boards

$
0
0
For a complete index of my stories click this text

As you will know I have written a book about the ESP32. It is in Dutch and undoubtedly you want to buy it for which you can find a link at the bottom of this page. In this book there are breadboard schematics which are designed with Fritzing. While using Fritzing extensively I stumbled upon a feature I did not know existed, and never have seen being used before.




I designed a small stripboard setup for neopixels which consist of some capacitors for stabilising the power supply and a resistor for attaching to the datalines. There is an USB connector on the board for supplying the power. You can read about this in my intro story about neopixels which you can re-read here: http://lucstechblog.blogspot.com/2015/10/neopixels-ws2812-intro.html



And I desgned a small stripboard for a DS18B20 thermometer chip.

Sidenote: thermometers are stupid. The internet of things is paved with thermometers and weather stations and I don't have a clue why everyone is building them. Presumably it's because they don't have anything better to make. Lack of creativity and fantasy. When I look outside my window I can see that it is raining or not and I can feel if it is cold or hot. I do not need a thermometer or weatherstation for that.
The only reason I think a thermometer is interesting is because it is a constant source of data which I can use for testing purposes.


So for the sake of this demonstration let us suppose that I am going to build a thermometer that displays the temperature on a strip of neopixels. Something like: below 20 degrees the pixels are blue and above the pixels are red.

What would I need.
Well a microcontroller like an Attiny85 or a Wemos D1
A Dallas DS18B20 thermometer chip with a pull-up resistor
A strip of neopixels.

Hey by coincedence I have designed two small stripboards with these items which I can use as a kind of building blocks. But they are all in separate Fritzing files.

Well here comes the trick.



First open Fritzing and start a new Breadboard setup. Put a Half breadboard on it and then put a Wemos D1 on that.



Open a new file. My version is in Dutch but just choose File and New.



In this new screem open the DS18B20 stripboard



Select the DS18B20 stripboard with all its components and just drag it onto the other window.
 





Do the same for the Neopixels stripboard



The last step is to select with your mouse one by one the stripboard with their parts and rotate them.
Now you only have to draw the wires and your project is complete.

I realise that in reality you (and I) work the other way round. First you build the project and then you make the Fritzing schematics. However Fritzing is great for documenting your projects like I am doing on this weblog.

I have used Fritzing for a long time now but never knew that it was so easy to bring parts from one design into another project. This works with stripboards and with breadbords. And it also works by choosing just parts of your design and transporing them to another board.

Till next time.
Keep experimenting you never know what you might find.

Luc Volders

Dweet again

$
0
0
For an index to all of my stories click this text

As you will recall as a frequent reader of this weblog my previous story introduced Dweet. A kind of cloud-based IOT messaging system to which you can send data using an API call. Next you can retrieve that data with another API call. All data is send publicly (unless you use a paid account) and can be retrieved by anyone if they happen to know the credentials. You can re-read that story here:
https://lucstechblog.blogspot.com/2019/05/dweet-volatile-iot-cloud-service.html

Months ago I wrote a story on how I build a thermometer. I am no fan of YAT (yet another Thermometer) however they have one big advantage: they are a source for data that can be used for testing. So look at the schematics and build yourself a version.  You can find all details here: http://lucstechblog.blogspot.nl/2017/11/oh-no-not-another-wifi-thermometer.html

Next step was to send the data from the thermometer to thingspeak. Read that story here: http://lucstechblog.blogspot.nl/2017/11/thingspeak.html

And then some time ago I wrote a story on how you could use the ping command to check if someone was at home or if all your network devices were working properly. You can re-read that story here: https://lucstechblog.blogspot.com/2019/05/ping-ping-anybody-home.html

And now we are going to send all this information to Dweet.

And again for rapid prototyping and quick results I am going to use ESPBasic as the devellopment environment. Read all primary information about installing and using ESPBasic here: http://lucstechblog.blogspot.nl/2017/03/back-to-basic-basic-language-on-esp8266.html

Sending thermometer values to Dweet

For starters I urge you to re-read the story about the thermometer and study the program thoroughly. Re-read the story here:
http://lucstechblog.blogspot.nl/2017/11/thingspeak.html

From the Dweet story we remember that the general API call is:

http://dweet.io/dweet/for/my-thing-name?hello=world

Let's adapt that for sending the thermometer value with ESPBasic.

First have a look at the most important lines from the Basic program: the lines that actually get the temperature:
test = temp(0)
test = ((int(test*10))/10)


The lines above get the temperature from a to an ESP connected temperature sensor (DS18B20) and round that to 1 decimal.

Next step is to look at the example I used in the story about Dweet. I send a fake temperature using the following line:

https://dweet.io/dweet/for/Lucstemp2018?temp=25

So the complete Dweet API call for the thermometer value would be:

https://dweet.io/dweet/for/Lucstemp2018?temp=test

Let's adapt that to a real ESPBasic command:

tosend$ = "dweet.io/dweet/for/Lucstemp2018?temp="&str(test)
helper$= wget(tosend$,80)
helper$ = ""


As you know by now Dweet wil send information back in the form of JSON code when you send information to the service. That is why I used the lines:

helper$= wget(tosend$,80)
helper$ = ""


This way the information that is send back will not be displayed on the screen but captured in a variable which is cleared immediately afterwards so the memory will not be cluttered up.

So here is the complete Thermometer program that sends the temperature to a webpage, Thingspeak and as well as to Dweet:


 tel=0  
Timer 5000, [start]

wprint "<!DOCTYPE html>"
wprint "<html> <body>"
wprint |<body style="background-color:greenyellow;">|
wprint |<H1><span style="color: red;">|
wprint " A thermometer"
wprint "</H1>"
wprint "</span>"
wprint |<H2><span style="color: blue;">|
wprint "Temperature is now "
textbox test

a = "background-color:greenyellow;"
a = a & "display:block;width:80px;"
a = a & "border-style: hidden;"
a = a & "font-size: 22px;"
a = a & "font-weight: bold;"
a = a & "color: fuchsia ;"
cssid htmlid(), a
wprint "</span>"
wprint "</H2>"
Wait

[start]
test = temp(0)
test = ((int(test*10))/10)
tel=tel+1
if tel = 360 then
tel = 0
gosub [thing]
endif
wait

[thing]
' send to Thingspeak
sendthing = str(test)
SENDTS("MP8Y1YLJUWZ4RTVR", "1", sendthing)

'send to Dweet
tosend$ = "dweet.io/dweet/for/Lucstemp2018?temp="&str(test)
helper$= wget(tosend$,80)
helper$ = ""
return


I made some tests and then retrieved the data from Dweet.

The Dweet documentation discusses an API call to get the last send data. The call's general form is:

https://dweet.io/get/dweets/for/my-thing-name

Adapting that for my Themometer that would be:

https://dweet.io/get/dweets/for/Lucstemp2018

I just put that in my browser and here is the result:


Sending Ping information to Dweet.

One of the previous stories on this weblog featured a method to test wether someone was at home and test if your network attached devices were up and running. I urge you to re-read that story and examine the source code thoroughly as we are going to use that to send the network status and the information about who is home to Dweet. So first re-read the original story here:
https://lucstechblog.blogspot.com/2019/05/ping-ping-anybody-home.html


The web-page the ESP makes looks like the page above.
Again this is done in ESPBasic.

Let's examine the part in the code were the program tests wether I am home or not by Ping-ing my phone's IP-adress.

lucphone = ping("192.168.1.67")
if lucphone = 1 then
io(po,D2,1)
lucphone = "at home"
else
io(po,D2,0)
lucphone = "he's not in"
endif

Well that part is easy. If lucphone = 1 then I am in and else I am out.

If I am going to send this info to Dweet I need to send the variable lucphone to Dweet. However the variable is used in some text. And I just want to send the plain data being 0 or 1. Why ? Just keep following this weblog it'll be explained in an upcoming story.
To do that alter this part of the program as follows:

lucphone = ping("192.168.1.67")
lucphone2=lucphone
if lucphone = 1 then
io(po,D2,1)
lucphone = "at home"
else
io(po,D2,0)
lucphone = "he's not in"
endif

As you can see I preserved the value of lucphone in a new variable lucphone2. And that is what we can Dweet.

Maybe you recall from the Dweet story that every sensor is called a 'thing' and needs a name. As I am not using the Thermometer ESP for this, but a separate ESP I am going to give this ESP another name being Lucshome.

For just Dweeting my phone info the API call looks like this:

http://dweet.io/dweet/for/Lucshome?phone=lucphone2

Let's transorm this to proper ESPBasic code:

tosend$ = "http://dweet.io/dweet/for/Lucshome?phone="&str(lucphone2)
a$= wget(tosend$,80)

However we do want to send all the information from our Ping program. So we have to create extra variables for each test just like we did for lucphone. So add the proper lines in the program for therm2, domo2 and elsphone2.

And then we get the following complete program:


io(po,D0,0)
io(po,D1,0)
io(po,D2,0)
io(po,D4,0)

timer1000,[testping]

wprint|<bodystyle="background-color:powderblue;">|
wprint|<H1><spanstyle="color: red;">|
wprint"Anybody Home ??"
wprint"</H1>"
wprint"<h3>Thermometer "

textboxtherm
cssidhtmlid(),"background-color:powderblue;border-style: hidden;font-size: 16px;display:block;width:80px"

wprint"<br>"
wprint"Domoticz "
textboxdomo
cssidhtmlid(),"background-color:powderblue;border-style: hidden;font-size: 16px;display:block;width:80px"

wprint"<br>"
wprint"Luc's phone "
textboxlucphone
cssidhtmlid(),"background-color:powderblue;border-style: hidden;font-size: 16px;display:block;width:80px"

wprint"<br>"
wprint"Els phone "
textboxelsphone
cssidhtmlid(),"background-color:powderblue;border-style: hidden;font-size: 16px;display:block;width:80px"

wprint"<br>"
button"QUIT",[progend]
wait

[testping]
therm=ping("192.168.1.65")
therm2=therm
iftherm=1then
io(po,D0,1)
therm="available"
else
io(po,D0,0)
therm="off line"
endif


domo=ping("192.168.1.66")
domo2=domo
ifdomo=1then
io(po,D1,1)
domo="available"
else
io(po,D1,0)
domo="Domoticz off line"
endif

lucphone=ping("192.168.1.67")
lucphone2=lucphone
iflucphone=1then
io(po,D2,1)
lucphone="at home"
else
io(po,D2,0)
lucphone="he's not in"
endif

elsphone=ping("192.168.1.72")
elsphone2=elsphone
ifelsphone=1then
io(po,D4,1)
elsphone="available"
else
io(po,D4,0)
elsphone="she's out"
endif

tosend$="dweet.io/dweet/for/Lucshome?therm="&str(therm2)&"&domo="&str(domo2)&"&lucphone="&str(lucphone2)&"&elsphone="&str(elsphone2)
a$=wget(tosend$,80)

wait

[progend]
io(po,D0,0)
io(po,D1,0)
io(po,D2,0)
io(po,D4,0)
end


And it works:




Caveats and pitfalls

I really enjoy playing with Dweet. However there are some serious caveats and pitfalls that you must consider.

Ever heard of number stations ?

These are radiofrequencies on which at certain times a day a list of numbers were send. It is a widely known phenomenon. Number stations were short wave transmissions alledgedly send to spies. Just Google "number stations" and a whole new world will open up to you. In the modern information age there are twitter accounts which are the equivalent of number stations. Look for example to these:
https://twitter.com/googuns_staging?lang=en
https://twitter.com/SierraGolf5
https://twitter.com/cynthiafortune
https://twitter.com/ZuluTango4
https://twitter.com/station_15a
https://twitter.com/ns111042

Well you can imagine that it is easy to use Dweet for sending secret information. Moreover since you can Dweet from a TOR browser so your IP adress can not be localised. Besides that the secret information can be disguised as genuine sensor readings. And after 24 hour the information is ereased !!! So nearly impossible to trace.

More down to earth.

In this story I Dweeted and used Lucstemp2018 and Lucshome as my 'things'.
Anybody reading this weblog knows that now. So anybody can put the following line in their browser and look at my data.

http://dweet.io/get/dweets/for/Lucstemp2018

Even worse. Anybody who has read this entry and the previous one can alter any Dweet they see at the Dweet webpage. So be carefull and responsible with this free service and do not spoil it for others.

Till next time
Have fun

Luc Volders

Fritzing using non-library parts

$
0
0
For an index to all my articles click this text

Fritzing is for me at this moment still the best program for aiding with my projects documentation. You will have seen a lot of breadboard designs and schematics made with Fritzing on this weblogt. I already gave you two valuable tips on Fritzing in previous articles.

The first one was that you could print your designs and overlay them one-on-one on your breadboard. You can re-read that story here: http://lucstechblog.blogspot.com/2019/01/fritzing-projects-duplicated-easy.html

The second tip showed how you could merge several fritzing designs in one. Great for using building blocks in your designs. Re-read that story here: http://lucstechblog.blogspot.com/2019/08/fritzing-merger-of-boards.html
For those who have never used Fritzing before I really recommend it. Check it out and use it to document all of your projects. Fritzing is free to use and can be downloaded here:
http://fritzing.org/home/

Fritzing Parts.

Fritzing is as said a great tool. Fritzing however depends on hobbyists like you and me to add parts to it's library. And new parts emerge every day. Next to that not all hobbyists who use Fritzing will use all the parts. So sometimes you will stumble upon a part you want to use which is not yet in Fritzing's library. What to do.

Well first there is the option of using Fritzing itself to design a new part. It involves tedious work in a drawing program (like Inkscape), being very accurate with measurements and have a great compassion for designing in general.

Not my cup of tea. Sorry. I would love to be patience enough to design new parts but I just cant bring myself to it.

So what to do.

Sometime ago I stumbled upon this 4 7-segment display which I wanted to use in a project. The item name was TM1637 and there was no Fritzing library part for it. However I wanted to document my project. So what to deo.

Well actually there is a way to get a picture of the part into Fritzing. It will not be in your parts library but you can use it anyway.




First start with taking a picture of the part.



Now clean it up. I use the Gimp for editing my photo's but you can use any photo manipulation program you like. When done save it as JPG.




Open Fritzing in Breadboard mode and go to the parts bin. Select the core parts.
And scroll down to the breadboard parts.


Select the last Icon. That is the icon for importing pictures. Drag it to your workspace.


Click on the icon on your workspace and look at the inspector. In the inspector select your picture.

Ok. Ok. from the above pictures you can see why I am not good at designing parts. Just look at those crummy arrows.......

The picture is loaded into your workspace. Scale it down to a usable scale.
Last step is to scale it to real-world measures. Best is done by orienting it to your breadboard so you can see the headers will fit the breadboard size.

That is it.
Now you can use the part like any other part from the fritzing library. There are however some restrictions.
- Every time you want to use the part you will have to load it again
- After loading you will have to resize it.
- No pinnumbers with descriptions will be shown
- The part is not up to real-life scale

I can live with these restrictions and just am glad I found a way to import non-library items.

Till next time
Have fun

Luc Volders

Dweet with Android

$
0
0
You can find an index of all my stories by clicking this text

For one reason or another I am still fascinated by Dweet. The possibillity to send and retrieve data anonymous intrigues me. Even more as that data is volatile. It disappears in 24 hours so the timespan to retrieve it is short. I see possibillities however have not yet a firm plan for using Dweet.

With Dweet you can send data from one or multiple ESP's, and you can retrieve it with one or multiple ESP's. It would be nice if you could Dweet with various apparatus and not only with ESP's. And actually you can.

In this story I am going to show you how you can send and retrieve data to Dweet with a self-build Android APP. In an upcoming story we are going to Dweet with a Raspberry Pi.

For those who do not have a clue on what I am ravelling about read the first two stories on Dweet.io: http://lucstechblog.blogspot.com/2019/05/dweet-volatile-iot-cloud-service.htmland 

THIS One: http://lucstechblog.blogspot.com/2019/08/dweet-again.html

App Inventor

Building APP's for Android phones and tablets is much easier as you might think. The MIT offers a complete setup which is free to use. The only thing you have to do is to get a free account and you can start devellopping Android App's no strings attached. You can even distribute them on Google Playstore and earn some mony with your APP's.

App inventor is a block-oriented programming technique just like Scratch on the Raspberry Pi or KBIDE for the ESP32 or Ardublock for the Arduino's.

I have used App Inventor form various projects on this web-log. Just look for them in my index-page: http://lucstechblog.blogspot.nl/p/index-of-my-stories.html

So start by pointing your web-browser to the App-Inventor http://appinventor.mit.edu/explore/
page. Start an account, look at the tutorials and documentation and start coding your own APP's.

Sending a Dweet



Let's look at the Designer screen. The App has 2 Labels that indicate what you need to fill into the textboxes. Next it has 1 button that will initiate the code that will send the Dweet and there is a hidden Web attribute.

In the first Textbox called Thingname you will fill in the name of your 'Thing' and in the second Textbox called Thingvalue you just fill in the valuen that you want to be Dweeted. The value can be a figure or a text. Whatever you want. This is just for testing purposes, we are not going to send real data.

Press the button and the data is send to Dweet.io

Let's have a look at the program block.


First we initialise a global variable called "Testval"

The program waits till the button is pressed. When that happens the variable "Testval" is filled with a string that contains all the information to send a Dweet. The first line is

https://dweet.io/dweet/for/

Then we add the value found in the textbox "Thingname"

?val=

is the next part of the line and the last part is the value found in the textbox "Testval"

Suppose we filled the name Dweettest in as Thingname and 125 as Thingvalue the complete text in the variable Testval would become:

https://dweet.io/dweet/for/Dweettest?val=125

And that is exactly what Dweet expects to receive. In the green part of the block the URL is set to get "Testval" which has the value https://dweet.io/dweet/for/Dweettest?val=125
And lastly the function is executed.





This is how it looks on the Android simulator and that's also how it will look on your phone's or tablet's screen.

Does it work ?

Well the only thing you have to do is to fill in the following URL in your browser:

https://dweet.io/get/latest/dweet/for/Dweetest and the result will be shown:





Receiving a Dweet.

So sending works. Now let's see if we can retrieve Dweets.

I build a seperate APP for that. You could combine it in one APP with two screens (one for sending and one for retrieving) or even do both on the same screen.



As you can see the top of the screen has a textbox in which you can fill in the Things name. Then there is the button that will perform the action when pressed. And further there are two textboxes that will display the received Dweet and an analysed version.
Lastly the listbox will show the actual received values.
There is one hidden component and that is the web component called Dweetconnect

When the screen has been setup you can move over to programming the blocks. This is more complicated.


Clicking the image will enlarge it which will make it easier to replicate the blocks for your own purposes.

First two variables are defined called DweetJson and Initval. These will be used to distill the information from the Dweet.

Next the program waits till the button is pressed and then it gets the Dweet for whatever is filled in into the Thingname textbox.

Then the real magic begins. Initval is set to the information which is in the "content" part of the Dweet. That is where the actual values are stored.

And the last part is where DweetJson is filled with the actual content.


As you can see it actually works as expected. When the name Dweettest is filled in in the Thingname field and the button is pressed the value 125 which was send previously is retrieved.

A practical example.

Remember the Thermometer http://lucstechblog.blogspot.nl/2017/11/oh-no-not-another-wifi-thermometer.html In the previous story I altered the software so it sends information to a webpage, Thingspeak and Dweet.io

If everything works well we should be able to retrieve the last temperature.



Above is the information on the thermometers web-page


And if you fill in "Lucstemp2018" as the Thingsname the temperature in my work-room is retrieved.

How about multiple fields ??



Here you can see the information that is found with my program that ping's my wifi devices like I described in THIS STORY and that I had the information Dweeted in this story.


And this is what it looks in my simple Android APP.

That's it for now. I bet you can find some usefull purpose for this. This POC (proof of concept) demonstrated how using Dweet.io it is easy to send information from an ESP to Android or from Android to an ESP.

Beware: keep in mind that this information is publically available for anyone who is actively looking for it. So be carefull with what you Dweet and do not use obvious names for your Thing.

Till next time
Have fun

Luc Volders

Dweet with Raspberry

$
0
0
For a complete index of all stories click this text


Introduction

This is my fourth story on Dweet but for those who have no knowledge about this service I will do a short introduction.

Dweet is a free service for IOT projects found at https://dweet.io/
Dweet is like Twitter for IOT projects. You send a message (sensor value or whatever) to Dweet.io and that message is stored for 24 hour. After that it is removed. Dweet.io remembers the last 5 messages you send to it. You can retrieve the message as many times as you like within those 24 hour. Dweet.io is totally anonymous. You even do not have to make an account for using the service. Dweet.io is used by many people all over the world. So how do you recognise which message is yours. You give your message a name called a 'thing' and a value. As long as you know the name of the 'thing' you can retrieve it's last 5 messages.

You can have multiple 'things' that all can Dweet and from each of them the last 5 messages are remembered for 24 hour.

For example you can have 3 ESP8266's which you give the thing names ESP1, ESP2, and ESP3. Each of these 'things' can send a message to Dweet containing sensor values. And if you want to know the value for the third ESP you just get the information for 'thing' ESP3 from Dweet.

I wrote 3 previous stories about Dweet.io on this weblog. The first described how to send and retrieve messages directly from your browser. Read that story here:

https://lucstechblog.blogspot.com/2019/05/dweet-volatile-iot-cloud-service.html

The second story described how to send and retrieve Dweets with an ESP8266 using ESP-Basic. Read that story here:

https://lucstechblog.blogspot.com/2019/08/dweet-again.html

And then I wrote a story on sending and retrieving Dweets with your Android phone using an dedicated app written with App Inventor. Re-read that story here:
https://lucstechblog.blogspot.com/2019/09/dweet-with-android.html

In this story I am going to show you how to send and retrieve Dweets with the Raspberry Pi. So when this story is completed you will have the means to send data using Dweet to any of your devices.

Raspberry Pi-Zero






I doubt that this small wonder needs an introduction. There are 2 versions. One with Wifi and Bluetooth and one without.
The Raspberry Pi Zero is more expensive as an ESP8266. The ESP costs about 3 Euro and the Raspberry around 11 euro. You do need a SD card to operate it which adds to the costs. However the Raspberry is a full Linux computer which is much faster as an ESP and has more memory and I/O ports. It can be equipped with a screen, keyboard and mouse like a full-fledged computer. However that not needed for IOT projects.

In this story I am not going to tell you how to set up a Raspberry. Neither am I going to tell you how you can use it headless (without monitor, keyboard and mouse) you can find all that information in about a 1000 stories on the web. In doubt go to the Raspberry Pi's official website and start there: https://www.raspberrypi.org/

Dweet with the Raspberry

For Dweeting with the Raspberry Pi I am going to use Python3. It is a bit more complicated as Dweeting with an ESP programmed in ESP-Basic but still no rocket-science. If you know the principles of programming in Python and are familiar with lists and dictionaries you can Dweet. If you need to learn Python I recommend SAMS book: https://lucstechblog.blogspot.nl/2017/08/learn-python.html

There is a Python library for working with Dweet called Dweepy. I have looked at it and find working with it not really easier as working without that library. So I am not going to use Dweepy but work directly from Python.

You do need 2 libraries however being REQUESTS and JSON. Both these libraries are included in the Raspberry's version of Python so nothing has to be installed.



Fire up your Raspberry and go to the Applications menu and start Python3 idle. I'll start with demonstrating how to Dweet with direct commands and put it all in a small program which you can modify for yourself later on.

Sending a Dweet with Python Idle

First thing to do is to import the REQUESTS library for internet information exchange and the JSON library to parse Dweet's answers.

>>> import requests
>>> import json


Now we need a value which we are going to send to Dweet. Let's use a fake temperature value and use that:

>>> temperature is 17.5

Dweet works with strings and the temperature value is a floating point variable. So lets change that:

>>> tempstring = str(temperature)

We now have the value that we are going to Dweet. Now lets make up a name for our 'thing'. For examples sake I call it Pyttemp.

Dweet says on its documentatio page that to send a Dweet you need to use the following format:

https://dweet.io/dweet/for/my-thing-name?hello=world

So let us translate that to Python:

>>> s = requests.get('https://dweet.io/dweet/for/Pyttemp?temp='+tempstring)

I put the command in the variable s so the answer of Dweet will not be printed on the screen.
That's all.

Go to your browser and in the URL field fill in the command for retrieving the Dweet from your thing which is in general form:

https://dweet.io/get/latest/dweet/for/my-thing-name

and in our particular case:

https://dweet.io/get/latest/dweet/for/Pyttemp
 

And there is your Dweet.

So this works. Easy !!

Retrieving a Dweet with Python Idle

Now we know that the Dweet has successfully been send we can retrieve it. This invloves a bit more work.

First we need Python to collect the Dweet. From the browser we just did that with the following command:

https://dweet.io/get/latest/dweet/for/Pyttemp

in Python this is translated in:

>>> r = requests.get('https://dweet.io/get/latest/dweet/for/Pyttemp')

The prompt will return but nothing is displayed. So lets see if the dweet was indeed retrieved:

>>> print (r)
<Response [200]>

Hey !! we do get a response but not what we expected. Actually the response tells us that the Dweet is indeed retrieved succesfully (code 200). However we want to get the actual information.
That is where the JSON library jumps in.

The JSON library parses the data from the JSON information we get back from Dweet.io. This is achieved by the following command:

>>> a=r.json()

Now we can print the information

>>> print (a)
{'by': 'getting', 'the': 'dweets', 'this': 'succeeded', 'with': [{'content': {'temp': 17.5}, 'created': '2018-02-18T14:47:14.080Z', 'thing': 'Pyttemp'}]}
And there it is. Next step is to distill only the information we need (Pyttemp) from this.

so let's see what a is:

>>> type (a)
<class 'dict'>

The variable a is a dictionary. That opens possibillities. We can retrieve the individual dictionary entries. First we examine what the entries are:

>>> for f in a: print (f)

by
the
this
with


We are interested in what is in the 'with'part. The following line retrieves that from the dictionary:

>>> b=a['with']

We now have retrieved part of the response. Let's have a look:

>>> print (b)
[{'thing': 'Luctemp182', 'created': '2018-02-18T10:28:46.312Z', 'content': {'temp': 19.5}}]

>>> type (b)
<class 'list'>

So b is a list. We have to get the first part out:

>>> b[0]
{'thing': 'Luctemp182', 'created': '2018-02-18T10:28:46.312Z', 'content': {'temp': 19.5}}

b[0] is a dictionary if all is well:

>>> type (b[0])
<class 'dict'>

From this dictionary we need to retrieve the 'content' entry which by the way is a dictionary in itself:

>>> c = b[0].get('content')

so the last step is:

>>> d=c.get('temp')

There we are:

>>> print (d)
19.5

Wow, Pfoeee !!!!!




The program

So it works in idle. Let's make a program out of it.



Start the program Editor Geany and paste the following code in:






importrequests
importjson
# next line dweets information
# it takes a floating point and converts it to a string
temperature=19.5
tempstring=str(temperature)
s=requests.get('https://dweet.io/dweet/for/Pyttemp?temp='+tempstring)
# next line retrieves the dweeted information
r=requests.get('https://dweet.io/get/latest/dweet/for/Pyttemp')


a=r.json()
print(a)
b=(a.get('with'))
c=b[0]
d=c.get('content')
e=d.get('temp')
print()
print()
print(e)


Run the program and:


We've done it.

Concluding

I do admit that this is a lot more complicated as Dweeting with an ESP8266 programmed with ESP-Basic. However this opens a lot of new possibillities. The Raspberry is cheap and has loads of IO ports. It's multitasking capabilities can have it Dweeting in the background while it is doing other tasks as well.

Till next time
Have fun !!!!

Luc Volders

Choosing colors for a webpage or for neopixels

$
0
0
For an index to all my stories click this text

This article was first published in my book about the ESP32 which is called ESP32 uitgelegd and is available in Dutch only at this moment. You can buy my book here: https://www.boekenbestellen.nl/boek/esp32-uitgelegd/9789463456814
You can find more information on this book here: http://lucstechblog.blogspot.com/2019/07/esp32-uitgelegd-nu-verkrijgbaar.html

In previous articles on this weblog I often published a program that runs on an ESP8266 or ESP32  and produces a webpage.

To fancy-up these webpages I gave them a backgound color of my liking. My chosing of colors may however differ from your likings. So I first show you how to pick colors the easy way.

<body bgcolor=PowderBlue>

Look at this line. It sets the background color for an entire webpage to PowderBlue. Where does that name come from ?

You can find all pre-defined HTML color names on the following webpage:

https://www.w3schools.com/colors/colors_names.asp

There are 140 names pre-defined.



Above you can see a few of the predefined names that you can use.

Likely you want still other colors. Well you can do that by alterning the code in such a way that it uses RGB codes which gives you much more freedom. The way to change the names in RGB code is as follows:

<body style = 'background-color:rgb(247, 2, 235)'>

But how to find these RGB codes. Well here is a neat trick.



Just open your browser and with your favorite search engine type the following search code:
rgb color picker

As you can see you are presented a large rectangle that is set at the hue's of a certain color. With the slider you can change the color and with the round dot you can specify the hue.

Beneath the rectangle you can see the values of that color presented in HEX, RGB, HSV HSL and CMYK.

Our interest is in the RGB values. So just alter the RGB values in your HTML code with the found RGB values in the color picker and you are all set.


Naturally this also applies when you are building an APP with MIT's APP-Inventor. By altering the RGB values you can alter the background color of your app.

Neopixels Bonus

As a bonus you can also use these RGB values to set the colors of your neopixels. There is just one flaw. It is difficult to produce brown colors. They will mostly tend to look orange-ish.

That is something I already noticed when building my resistor code watch:
https://lucstechblog.blogspot.com/2016/10/nuw-resistor-color-code-clock.html

Till next time
keep tinkering and have fun


Luc Volders

Freeboard

$
0
0
For an index to all my stories click this text

Freeboard is a cloud based free service that allows you to display your sensor (IOT) data in a pretty way. However to display your data on freeboard you will have to Dweet your sensor values. So before you start reading this story I urge you to read the previous stories that discuss Dweet in depth. You can find those stories in the following links:

Dweet - A volatile IOT Cloud service 
Dweet again - Have your ESP8266 send data to Dweet with ESPBasic
Dweet with Android - Design an APP to use Dweet on your Phone
Dweet with Raspberry - Completing the line you can dweet now from any device
 
As you recall from these stories we can send data to Dweet and retrieve it again as text. This can be very usefull however most of the time you would like your data to be presented in a nice graphical way. That is where Freeboard comes in. Freeboard is a service that present the data from Dweet in a nice graphical way. When I tested Freeboard and wrote this story the service was free to use. Bad thing is that Freeboard is no longer free. A paid account is required. However you can try and use it for a month for free. Within this month you may decide wether you find it worth it.



There is a way to achieve the same as described here with Node-Red. And Node-red is free to use. You can build a Freeboard-like server with a Raspberry Pi and Node-Red. This is something I will adress in a future story.

First step is to go to the Freeboard.io website and register for a account.



Pressing START NOW brings you to the page where you can register for an account. If you already have an account you can SIGN IN on the top right side of the screen.

On the next page you can choose to alter your account settings and have the option MY FREEBOARDS. When this is your first time working with Freeboard choose for creating a new board. I called it My Home.



At first you have an empty screen.
This is where all the data will be displayed

As said before, Freeboard displays data that is Dweeted. Therefore you need first to Dweet some data. In the stories about Dweet I showed you how to do that. You can now Dweet some fake data. You can also use the values from my personal thermometer. I told you thermometers are stupid, however usefull for testing purposes......... So let´s have a look at my thermometer Dweets. My ´Thing´ is called Lucstemp2018 and the thermometer value is in the variable `temp´. Let us use that.

The first thing to do is to tell Freeboard where the data is coming from. On the top right side of your screen where it says DATA SOURCES click on ADD



Choose Dweet.io




Now give this datasource a name. I called it (obviously) thermometer and fill in your things name. And save.

For my thermometer I am going to make two graphical presentations. First a Gauge and second a line diagram.


Start by clicking on the left top side of the screen on ADD PANE. As you can see a new pane has been added to the screen.
You can click it and move it around on the screen to place it where you want it. For now let is be where it is.


Click on the wrench so you can edit the basic information for this pane. As the title I chose Mancave Temperature and did not alter the number of columns.




Now press the + sign and a screen opens in which you can enter the details of your widget. Choose Gauge.


Fill in the details on the Gauge. I named it Actual Temperature. In the value field click on the line next to it: Datasource and you will be presented by the name of your 'thing' and the data from it (temp). For units I choose Degrees C and as Minimum and Maximum values I choose -5 and 60. Choose SAVE again and that's it.



As you can see the Gauge is displayed immediately. And as you can see it is not very hot in my work room.

Now let's add the actual time to this information board.

Start with Adding a DATASOURCE (top right side of your screen) and choose Clock.


Fill in the details. I just called it time and left the refresh rate at every second. Save.


Now add a pane again. You can see on the top right side of the page which data sources are accessible at this moment (Thermometer and Time).


Click on the wrench of this pane to give it a name.


Choose text


Again fill in the details of this data source. Give it a name and the size you want it displayed. And use as DATASOURCE the just added TIME and use 'full string value


And there you are. You can actually see when I wrote this story........

Now let us move back to the MANCAVE TEMPERATURE pane and press on the + sign.


As type choose sparkline.


And fill in the details. I gave it the title TEMPERATURE HISTORY and as data source I used the same Thermometer and the variable 'temp'

And as you can see after a while a nice diagram is showing that displays the temperature over time.

Rests only one last possibillity.
Remember the sory about how you could PING IP adresses to see if a network attached device is working or if someone is at home ??? Well re-read the sory here. 


https://lucstechblog.blogspot.com/2019/08/dweet-again.html

In that sory we added a line to the PING program to Dweet the information. Well we are going to pick that info up and display it on our freeboard.

tosend$ = "dweet.io/dweet/for/Lucshome?therm="&str(therm2)&"&domo="&str(domo2)&"&lucphone="&str(lucphone2)&"&elsphone="&str(elsphone2)
a$= wget(tosend$,80)


These were the lines in our basic program that send the information to Dweet.
So thing 'thing' is called Lucshome and the variables are therm, domo, lucphone and elsphone.

What I want is just a simple indicator that displays wether the Thermometer is working, Domoticz is working and wether me or my girplfriend are at home.

First add a new DATASOURCE





Again use Dweet.io as the type, and Lucshome as the name of the 'thing'



Now make a new pane. I called it "Who is at home"





Add a widget and choose Indicator light as the type.


Fill in the details.
The widget will indicate if I am at home or not. So I called it "Where is Luc". The DATASOURCE is the just added "Who is at home" and the variable is "lucphone".



In the same pane click again on the + sign and add another widget. This time for Els'es phone.


And as you can see we have now 2 indicator lights that show wether Els and I are at home.

And that's about it.

There are many more possibillities with Freeboard. You can add a Google Map with location details, add pictures, add a pointer that works like a compass, add text and HTML code. So you can have a lot of widgets on your screen. And as you saw in the example above. You can have information from multiple ESP's on your screen. Did you know by the way that you can also Dweet with a Raspberry. That opens even more possibillities.

And best of all you can have multiple boards on one account. So you can make boards for your home, work, garden, aquarium etc etc etc.

Privacy, what privacy ??

Well as you have learned from the Dweet stories: everybody can see your data when they know your 'things'name. There is however so much data Dweeted every moment that, when you choose a secret 'thing' name it will be difficult to find your specific data.

Freeboard needs you to log in to alter the boards and widgets.
However when a board is finished or being build you can see in the URL of your browser the ID of the board.


So if anyone is looking over your shoulder when you are building your board and notes down the URL he can look at your board without having to log in. So be carefull what information you give/show to who.

Till next time.
Have fun

Luc


IoTtweet part 1

$
0
0
For a complete index of all my stories click this text

As you know there are several ways to control your IOT projects.
You can read sensor data and send command to an ESP8266 with a dedicated app on your phone, with a webpage generated by an ESP8266, with a Raspberry Pi or using a cloud based service.

I have written several stories about cloud based services. There is a story on Thingspeak: http://lucstechblog.blogspot.nl/2017/11/thingspeak.html and there are several stories on Dweet: http://lucstechblog.blogspot.com/2019/09/dweet-with-raspberry.html and on Freeboard: http://lucstechblog.blogspot.com/2019/10/freeboard.html 

There is nothing wrong with these services however they lack something. They lack a simple button on the screen which you can press to light a lamp or start a pump etc.

There is another service which displays sensor values graphically on your browser screen like graphs and gauges. However this service also has the ability to put switches and sliders on the webpage which you can read with an API call from your ESP8266. This is also a free service and is called IoTtweet. The webpage is called accordingly: iottweet.com

IoTtweet

 



Here you can see an example page called a Dashboard with all kinds of information on it. You can see several graphs a gauge a slider and a switch. This is what I am going to show you how to build.

You can design 10 of these Dashboards freely. And each dashboard can contain:
- 1 Profile picture
- 4 Gauges
- 4 Charts
- 5 Switches
- 4 Sliders

I'll guide you through all the designsteps.

Start with IoTtweet.com



Point your browser to iottweet.com and from the menu on the top of the page choose LOGIN.
From this page you can login with your user name and password if you have created an account earlier. Or you can choose for signing up for a new account.








After Signing in or creating an account go to the menu entry DASHBOARD.

As you can see I have already created 2 Dashboards. One is called Testthing the other Homepage. I blackened out the keys for these pages so you will not be tempted to mess up my dashboards.....

At the bottom of the page you can create a new dashboard by inputting a name (Thingname) and IOT model. These are not critical and you can fill in anything you like. The important thing is that there is a key generated for the Dashboard and you will need that key for sending and retrieving data.

The hardware

For sending data to iottweet I made a simple setup.



I am using an ESP8266 with attached a Dallas DS18B20 temperature sensor, 2 pushbuttons and 2 led's. That is enough for the demonstration purposes. For following this story I suggest you build the same setup. If you do not have a DS18B20 at hand use a potmeter connected to the analogue port of the ESP and adjust the software accordingly or simply make a slider so you can easily send altering values.


Designing your dashboard.

So let us start with designing our first dashboard. I called it Homepage.



On the top left you will see a button called Edit Layout. Click that and the dashboard becomes a grid



As you can see buttons appear for adding charts, gauges, switches, sliders and various other things to your dashboard.
Let us start with adding a Gauge to the Dashboard.



Just click on the Create Gauge button and it appears.



Click on settings and a seperate window opens in which you can make adjustments. There are 4 so called slots for feeding data to your Gauge called Slot 0 - Slot 3.
As this is the first slot we are going to use we use Slot 0.


Fill in the rest of the details. I gave my Gauge the name Temperature as units I choose Degrees C and as maximum I used 50. Don't forget to save.
The gauge will display (patience, paptience) the momentary temperature from the DS18B20. However I also want to see some temperature history. So we will make a chart for that.

Just click the Chart button and a new chart will appear. It will be situated on the top left point of the grid and that will be under your guage. So move the parts with your mouse to any poitn on the grid you like. When they are where you want them click the settings button on the chart.



For data input we choose the same Slot. So as you can see you can have a gauge and a chart representing the same data, and that is just what we want in this case. So we still have 3 data slots over for representing other sensors etc. And each of these slots can be represented on the dashboard by a gauge, chart or both.
I called this Chart Temperature and the Y axis will represent Degrees Celsius wuith a minimum of -15 and a maximum of 50. You can even adjust the color of the line and infill.

Now add another chart and call it Switch. Attach it to slot 1 and give it the minimum value of 0 and maximum of 1.



Save the layout. And your page will look like the picture above.

Now click the Iotgarage button and your back on the page where the list of your Dashboards appear. The most important part here is the key. You will need that to send data to your dashboard. On the top right of your screen you can see your login name and UserID. You'll need the UserID to. So just keep this screen open.

IoTtweet API

To send data to IoTtweet there is a simple to use API.

WriteDashboard(userid,key,data0,data1,data2,data3,private_tweet,public_tweet)

Simple !!
Just fill in the UserID, Key and the data for the 4 slots and youre done.

ESP-Basic

On the IoTtweet page you will find a link to Github where you can find example programs for the ESP in C++ (arduino) which should undoubtedly work on the ESP32 to. However I am going to use my favorite rapid devellopment environment: ESP-Basic.

For detailed information on installing and using ESP-Basic I wrote a tutoarial which you can find here: http://lucstechblog.blogspot.nl/2017/03/back-to-basic-basic-language-on-esp8266.html

So fire up the ESP-Basic editor and copy and paste the next program:

io(po,d6, 0)
io(po,d7, 0)
but1p = 0
interrupt d1, [sendbut]
timer 10000, [sendtemp]
wait

[sendtemp]
    value = temp(0)
    sendapi$ = "api.iottweet.com/?userid=001305&key=7w1mlo282rtn&slot0="&str(value)&"&slot1="&str(but1p)
    b$= wget(sendapi$,80)
    b$=""
wait

[sendbut]
    but1p = 1 - but1p
    sendapi$ = "api.iottweet.com/?userid=001305&key=7w1mlo282rtn&slot0="&str(value)&"&slot1="&str(but1p)
    b$= wget(sendapi$,80)
    b$=""
        delay 200
        interrupt d1, [sendbut]
wait

As you can see the program is very simple. The most complicated part is combining all the data into sendapi$. Do not forget to fill in your own userid and key for the x and y values.

A closer look at the program.

First the program sets a timer which jumps every 10 seconds to [sendtemp].
In the routine [sendtemp] the temperature is read from the DS18B20. Next the API call is composed. The values which we send have to be strigs and therefore the value of the temperature is converted to a string with:

str(value)

The program also sets an interrupt which is triggered when you press the button attached to D1. When this button is pressed the program jumps to [sendbut]. In [sendbut] the value of the button is inverted. A 0 becomes 1 and a 1 becomes zero. This way the button is toggled on and off. Next the API call is build in sendapi$ and send with wget.

b$= wget(sendapi$,80)

This line makes sure the API call is send but not displayed on the ESP's screen.

Next a we wait for a while with the delay command for debouncing the button and then the interrupt is re-initiated.



And here is how it looks in real-life. Unfortunately there was no temperature fluctuation. As you can see the button was pressed on random occasions.

So far so good.

Up to this part there is not much difference with Freeboard which we discussed earlier in this story http://lucstechblog.blogspot.com/2019/10/freeboard.html exept that the IoTtweet board is private so can not be accessed by anyone but you unless they have your login codes. And off-course IoTtweet is free to use.

The biggest difference is that IoTtweet is capable of sending commands back to the ESP. That's something I will show you next week. So keep coming back and make sure to:

Have fun

Luc Volders

IoTtweet Part 2

$
0
0
For a complete index of all my stories click this text

This is the second story on IoTtweet.

IoTtweet is a cloud service that let's you manage sensor data on a remote service which you can access from anywhere in the world. It is a service like Thingspeak and Freeboard but has an extra feature which makes it simple to put sliders and switches on the Dashboard.

If you not have read the previous installment I urge you to do so because that explains how to log in, design Dashboards and gives basic information on accessing the API. You can read that story here: https://lucstechblog.blogspot.com/2019/10/iottweet-part-1.html

Controlling the ESP-8266 from IoTtweet

Until now we have send information from the ESP to IoTtweet. Now we are going to control the ESP from our Dashboard.



At this moment the Dashboard looks like above. That is if you followed the instructions in the previous story. To control the ESP we are going to add a switch and a slider.




Click on the Edit Layout button and the Dashboard will become a grid again. Click on Create a Switch.

The switch will appear below the gauge so move it with the mouse to a convenient space. When positioned click on set.




For Digital Input port you have 5 choices. So you can add 5 switches on your Dashboard. I used Port 1 and called it Switch 2



Next step is to put a slider on the Dashboard. Just click Create slider and it will appear. Again it will appear under the Gauge so move it to a convenient free space and click on setting.



You can put 4 sliders on your Dashboard (port 1 to port 4) and give them any name you like. I called mine Led Dimmer as that is what I am going to use it for. You can not alter it's values. They are automatically set from 0 to 100. So to use different values, like PWM 0 to 255 or servo 0 to 180, you will have to make adjustments in your ESP's program.

I did one last adjustment. I added a profile picture.

Click on the settings button of the profile picture and you can add an URL of a picture somewhere onn the internet. IoTtweet suggests you upload a picture to postimg.org and use the URL you will get from that service. I did so and it worked great. postimg.org is something worth checking out.

Save the Dashboard and we are done.

The hardware



We are using the same setup as used in the previous story. And we were anticipating already on the complete setup as there are 2 leds on the breadboard as you can see.
We are going to set one led ON or OFF with the switch and we are going to set the brightness of the other with the slider.

The API call

The API call for getting the slider and switches values is different from the API call that sends data to IoTtweet. The general function is this:

.ReadControlPanel(userid,key);

We can translate that to ESP-Basic code with the following line:

a$ = wget("api.iottweet.com/read/?userid=XXXXX&key=YYYYYYYYY",80)

You need to replace the XXX and YYY with your own credentials on the IOT-Garage page.

The answer we get back is:

{"0":"ON","sw1":"ON","1":"OFF","sw2":"OFF","2":"OFF","sw3":"OFF","3":"OFF","sw4":"OFF","4":"OFF","sw5":"OFF","5":"39.000","slide1":"39.000","6":"0.000","slide2":"0.000","7":"0.000","slide3":"0.000"}

Let's examine this:

"0":"ON","sw1":"ON"
"1":"OFF","sw2":"OFF"
"2":"OFF","sw3":"OFF"
"3":"OFF","sw4":"OFF"
"4":"OFF","sw5":"OFF"

"5":"39.000","slide1":"39.000"
"6":"0.000","slide2":"0.000"
"7":"0.000","slide3":"0.000"

There they are: 5 switches and 3 sliders.

To get to the data we can use the build-in Json parser in ESP-Basic.

switch = json(a$,"sw1")
slide = json(a$,"slide1")

Just replace "sw1" with the name of the switch you are looking for and "slide1" with the name of the slider.

Piece of cake.

The ESP-Basic Program.

What I did was a simple alteration to the first Basic program. The previous program send the measured temperature every 10 seconds to IoTtweet. I put a subroutine in that at that time checks the switch and the slider value.


io(po,d6,0)
io(po,d7,0)
but1p=0
interruptd1,[sendbut]
timer10000,[sendtemp]
wait

[sendtemp]
value=temp(0)
sendapi$="api.iottweet.com/?userid=XXXXX&key=YYYYYY&slot0="&str(value)&"&slot1="&str(but1p)
b$=wget(sendapi$,80)
b$=""
gosub[getdata]
wait

[sendbut]
but1p=1-but1p
sendapi$="api.iottweet.com/?userid=XXXXXX&key=YYYYYYYY&slot0="&str(value)&"&slot1="&str(but1p)
b$=wget(sendapi$,80)
b$=""
delay200
interruptd1,[sendbut]
gosub[getdata]
wait


'==============================
'readvalues
'==============================
[getdata]
a$=wget("api.iottweet.com/read/?userid=XXXXXX&key=YYYYYYYYY",80)
switch=json(a$,"sw1")
slide=json(a$,"slide1")
ifswitch="ON"then
io(po,d6,1)
but1p=1
else
io(po,d6,0)
but1p=0
endif
io(pwo,d7,(val(slide)*10))
return


As usual replace the XXXX and YYY values with your own IoTtweet credentials.

The first led is then put ON or OFF depending on the setting of the switch and the other led is dimmed depending on the slider value.

This is very basic (pun intended) and needs to be altered for your own projects but it clearly demonstrates the possibillities.

The sliders can be used not only for dimming leds or lamps but also for setting the speed of a motor or the angle of a servo. Use your imagination.

Till next time
Have fun

Luc Volders

ESP-01 programming board (new)

$
0
0
For an index to all my stories just click this line

First let me refresh your memory. Next to the NodeMCU and Wemos D1 Mini boards there is still the ESP-01 board available. It is not as popular as the other versions because it only has 2 I/O ports and no USB interface. However for building simple sensors like a thermometer or movement detector etc it is excellent. It uses not a lot power because the lack of USB chips etc.




Long time ago, November 2015 to be exact, I wrote a story about building your own ESP-01 programmer. You can re read that story here.

http://lucstechblog.blogspot.com/2015/11/esp8266-01-programming-board.html 
It is bulky and needs an FTDI (USB to serial adapter) but does the job flawlessly.





Now there is an alternative. And it is much cheaper as my DIY version. You do not need a separate FTDI, nor a piece of PCB, buttons etc. It is all inclusive, and a lot less bulky.




The trick is on this side.




The button puts the module in programming mode when slided to the ESP header. When the button is slided towards the USB connector the module is in communication mode. That's all. I use it frequent lately on a Windows 10 computer system without any problems.



The only flaw in my opinion is that it lacks a reset button. So to reset it you have to cut the power supply. The good part is it's small size and has a cheap price.

So when you are starting with using ESP-01 modules and want a cheap programmer this is a good solution. Just beware that you buy the one with the switch cause there are a lot of these look-alikes without the switch and those are just usable for communication and not for programming.

For those who need a quick reminder I also give you here the link to my story about the programming software for the ESP-01. Only needed if you are going to use ESP-Basic or Lua.
http://lucstechblog.blogspot.com/2015/11/flashing-esp8266.html

Till next time.
Have Fun

Luc

Dweet with Arduino

$
0
0
For an index of all my stories click this text

Oh no not Dweet again !!!
Well yes but due to popular demand.

Introduction

For those that do not know what Dweet is I give you a short introduction.

Dweet is a free service for IOT projects found at https://dweet.io/
Dweet is like Twitter for IOT projects. You send a message (sensor value or whatever) to Dweet.io and that message is stored for 24 hour. After that it is removed. Dweet.io remembers the last 5 messages you send to it. You can retrieve the message as many times as you like within those 24 hour. Dweet is totally anonymous. You even do not have to make an account for using the service. Dweet.io is used by many people all over the world. So how do you recognise which message is yours. You give your message a name called a 'thing' and a value. As long as you know the name of the 'thing' you can retrieve it's last 5 messages.

You can have multiple 'things' that all can Dweet and from each of them the last 5 messages are remembered for 24 hour.

You can have for example 3 ESP8266's which you give the thing names ESP1, ESP2, and ESP3. Each of these 'things' can send a message to Dweet containing sensor values. And if you want to know the value for the third ESP you just get the information for 'thing' ESP3 from Dweet.

I wrote 4 previous stories about Dweet.io on this weblog. The first described how to send and retrieve messages directly from your browser. Read that story here: 

https://lucstechblog.blogspot.com/2019/05/dweet-volatile-iot-cloud-service.html

The second story described how to send and retrieve Dweets with an ESP8266 using ESP-Basic. Read that story here:

https://lucstechblog.blogspot.com/2019/08/dweet-again.html

To get Dweeting with Android read this story:
https://lucstechblog.blogspot.com/2019/09/dweet-with-android.html 

And we can Dweet with the Raspberry:
https://lucstechblog.blogspot.com/2019/09/dweet-with-raspberry.html
 

So why another story ?

Popular demand like I said.
Well actually I received some mails in which people stated that they wanted to use Dweet with an ESP8266 but were not willing to switch to ESP-Basic. They wanted a solution in C++ (Arduino). Well here you go.

The Arduino Code



#include <ESP8266WiFi.h>

constchar*ssid="ROUTERSNAME";
constchar*password="ROUTERSPASSWORD";

StringthingName="Arduintemp";
constchar*dweetsite="dweet.io";

intstopval=1;

voidsetup()
{
Serial.begin(9600);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid,password);
intretries=0;
while((WiFi.status()!=WL_CONNECTED)&&(retries<15))
{
retries++;
delay(500);
Serial.print(".");
}
if(retries>14)
{
Serial.println(F("WiFi conection FAILED"));
}
if(WiFi.status()==WL_CONNECTED)
{
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/");
}
Serial.println("Connected and ready to send");
}

voidloop()
{
dweetdata();
}

voiddweetdata()
{
WiFiClientclient;
constinthttpPort=80;
if(!client.connect(dweetsite,httpPort))
{
Serial.println("connection failed");
return;
}

Stringdweetstring="GET /dweet/for/";
dweetstring=dweetstring+String(thingName)+"?";
dweetstring=dweetstring+"temp=";
dweetstring=dweetstring+"12";
dweetstring=dweetstring+" HTTP/1.1\r\n"+
"Host: "+
dweetsite+
"\r\n"+
"Connection: close\r\n\r\n";

client.print(dweetstring);
delay(10);//wait a bit for stability
while(client.available())
{
Stringline=client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("Finished");
while(stopval==1)
{
delay(10000);
}
}


The program is straightforward and anybody who claims that Arduino code is their favorite should be able to decipher it easily.

I will highlite some bits though.

const char *ssid     = "ROUTERSNAME";
const char *password = "ROUTERSPASSWORD";

Fill in your own credentials otherwise you will have no connection to the internet.

The first part in the setup routine should give you no problems in understanding what is happening. It is the loop where you should pay attention to.

  String dweetstring="GET /dweet/for/";
  dweetstring=dweetstring+String(thingName)+"?";
  dweetstring=dweetstring+"temp=";
  dweetstring=dweetstring+"12";
  dweetstring=dweetstring+" HTTP/1.1\r\n"+
      "Host: " +
      dweetsite +
      "\r\n" +
      "Connection: close\r\n\r\n";
   
  client.print(dweetstring);

This is the part that actually builds the message and Dweets it.

String thingName="Arduintemp";

Thingname was defined at the start of the program.

const char* dweetsite = "dweet.io";

And so is dweetsite the name of the host.

dweetstring wil be the text that is Dweeted. The variable name will be "temp" and its fixed value in this example = "12"

Feel free to replace the 'thing' name with any name you like and do the same for the variable and it's value.

  while(client.available())
    {
    String line = client.readStringUntil('\r');
    Serial.print(line);
    }

These lines clear the wifi buffer.

  while (stopval ==1) 
  {
    delay(10000);
  }

And this makes sure that the routine is run only once.

If this is going to be used to send sensor information at a regular interval you could use Deepsleep here to save power. If you do not have any idea on what Deepsleep is read this story http://lucstechblog.blogspot.com/2018/07/esp-power-reduction-withn-deepsleep.html

The Result




Like I demonstrated in the first story about Dweet I just pulled the information from Dweet.io with my browser.

Famous Last Words

Well here you have it. Arduino Code to Dweet with the ESP. Now send me a mail with a link or description of the projects you made with this.Now go back to the ESP-Basic version and look how I get the same result with just a few lines of code. You choose !!

Till next time
Have fun !!!

Luc Volders

Sending data from ESP to Android

$
0
0
Click here for an index of all of my stories

I have written about many projects that use an Android Phone or Tablet to command an ESP. There are several ways to do that.
You can use a dedicated APP written in Mit's App Inventor like this story explains: http://lucstechblog.blogspot.nl/2018/02/wifi-voice-commander.html or this story https://lucstechblog.blogspot.nl/2018/01/wifi-relay.html
You can also have a web-page on the ESP that has buttons and sliders which can be accessed from any browser including your phone's or tablet's like this story (programmed in LUA) https://lucstechblog.blogspot.nl/2016/05/esp8266-controlled-ledstrip.html or this story https://lucstechblog.blogspot.nl/2016/08/rain-sensor-using-esp8266.html or the Relay server https://lucstechblog.blogspot.nl/2016/09/esp-relayserver.html and of course the obvious thermometer: http://lucstechblog.blogspot.nl/2017/11/oh-no-not-another-wifi-thermometer.html

All these projects have one thing in common. The Android phone or Tablet sends data to the ESP. It is never the other way round.

Searching the internet I did not find any project in which an ESP8266 send data to an Android device where the Phone or Tablet is used to process the data or just to display it. And for a certain project (still in devellopment) that was just what I needed.

So I had to find it out for myself. And actually it turned out to be much easier as I expected.

There are 2 sides to this story The ESP side and the Android side.

The ESP side

I wanted a quick and dirty solution so I used ESP-Basic for this. If you want an introduction to lean to work with ESP-Basic read this:  https://lucstechblog.blogspot.nl/2017/03/back-to-basic-basic-language-on-esp8266.html

The basic (pun intended) point is that we want to have the ESP react on an incoming request. I did that before when I let the ESP react on a message send to it from IFTTT in this story: https://lucstechblog.blogspot.nl/2017/05/google-home-and-esp8266.html

And actually I did the same in Arduino language (C++) in this story:
https://lucstechblog.blogspot.nl/2018/01/wifi-relay.html

Both these stories let the ESP react on an incoming request but that is not what I wanted. I wanted the ESP to send data to the device that send a request. And that involves just a light modification of the code.



msgbranch[mytestbranch]
wait

[mytestbranch]
a=a+1
myreturn="test number "&str(a)
printmyreturn
msgreturnmyreturn
wait

The msbrach just waits till the ESP receives a message. It is not important what the contents of the message is. We do not even check it.

When a message is received the program jumps to the [mytestbranch] routine.
In there the variable "a" is increased and a return message is send to the device that send the request.

Piece of cake.

The Android side

The Android program is made with Mit's APP-Inventor. If you do not have any experience with writing APP's for Android please take a look at APP-Inventor. It is easy to use and works like Scratch on the Raspberry or other block-oriented programming environments.



Start with designing a screen that contains a button and a label.
The label is the small green dot just below the button.

Now switch over to the block side and here is the program:



This part has a few flaws. It works but remember this is only a proof of concept.

The first block defines what happens when the button is clicked. And that is easy. A 'get' request is send to the ESP's IP adress. Finding the ESP's IP adress can be done in several ways. In ESP basic:

print ip()

will do the trick. Another way is to open your router's web page and look there for the IP number of the ESP. I described that in several stories here on this weblog. For example in this story:
https://lucstechblog.blogspot.nl/2018/02/esp-voice-control-with-esp-basic.html

You could make this program universal by adding a text field in which you can type the IP-adress. That way this small program can be usefull for getting information from a number of ESP's. Just be creative.

The next block is activated when a request has been received and a return message has been send.
The text in the label is then set to the response.

That is all folks.

Real world

The Basic program prints on the screen of it's web page what is send to the Android device. As you can see I have pressed 8 times on the button on my Android Phone.


The Android device, which is my phone but could also be a tablet or whatever, displays the last received data from the ESP.

Expanding the code

Here are several ideas to expand the code.

- Like stated above add a text field in the Android program/screen so you can fill in the ESP's IP-number
- Send multiple data to the Android Device
- Make this a two way conversation. For example the Android Device asks for certain information like a number, temperature, sensor data or whatever and let the ESP respond with the right information.
- Let the Android Device switch on a lamp, pump, motor etc and let the ESP respond if it is done so you are sure things work as you'd expect.

I think you can come up with a lot of projects and ideas for this.

Till next time
Have fun

Luc Volders

ESP32 Brownout problem

$
0
0
For an index to all my stories click this text

I have been doing a lot of tests and projects on the ESP32. And just as with the Arduino or ESP8266 you just write a program, upload it from your computer and it works.

And then suddenly I encountered some severe problems.



The programs would not start and the Serial Monitor showed the above text: Brownout Detector was triggered. This did not occur all the time but only when some heavy programming was involved. In my particular case it happened when I was develloping a program that included multiple libraries:


#include <Time.h>
#include <TimeLib.h>

#include <WiFi.h>
#include <NTPClient.h>
#include <WiFiUDP.h>

And an extra speech synthesizer library, on which I'll come back in a later story.

Please note that I am using the ESP32 Devkit board V1 from DOIT. This problem might not occur with other boards. I also noted that the problem occured when Wifi was activated (and therefore power consumption was increased).

Brownout detection.

I thought it was strange that this error occured as I knew from the Attiny 85 micro controllers that Brown-out Detection (BOD) is activated when the chip gets to low Voltage. And I had nothing attached to the ESP32. So nothing was drawing power except the ESP32 itself. Therefore the voltage should not get too low for the microcontroller to work.
Nevertheless the ESP32 detected the brownout and kept resetting itself.

Searching the internet revealed that many others encountered the same problem and some solutions were suggested:

- You are using a poor quality USB cable. Try to use a good quality one
- The USB cable is too long. Use a shorter one
- Bad computer USB port. Attach the ESP32 to another port
- Not enough power supplied through the USB port: Use a USB Hub with an external power supply.

I tried all of these suggestions and it did not help.

The solution.

In the end I found a software solution and I do not want to keep that from you.

The solution is to disable the Brown-Out Detection. This is obviously a makeshift solution as there is something wrong with the Devkit ESP32's power supply. But it works like a charm.

Start your program with the following lines:


#include "soc/soc.h"
#include "soc/rtc_cntl_reg.h"

#define nobrownout true
#define lowtxpower true

In the start of the setup routine add the following line:


if(nobrownout)WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG,0);

This seems to solve the problem.

From the moment I incorporated these lines into my ESP32 programs I did not encounter this problem again.

Solution number 2

I started experimenting and I found another solution.

It occurred to me that the Brow-Out Detection was triggered by a Voltage drop. I was programming my ESP32 from my USB port and when the programming was finished the ESP32 rebooted and started its program. The ESP32 however was still attached to the USB port of my computer. This way I could monitor the proceedings over the Serial Port.

So I decided to program the ESP32 with my computer and then attach the ESP32 to a power bank. I have a big powerbank which has 2 outputs. One supplies 1A and the other port supplies 2A.

Guess what. This solved my problem.
So it seems that the USB port of my computer is not capable of supplying enough power to get the ESP32 fully working.

This also worked with a USB power supply.

The setback is that this is only good when your program is finished as you are not able to monitor anything through the Serial Port.

Solution number 3

This one is a bit tricky, so you have to be absolutely sure of what you are doing.
I decided to use a double power supply for the ESP32.



I plugged the USB port of the ESP32 into my computer and attached a second power USB supply to the V-IN pin of the ESP32 and that worked flawlessly !!! Be aware that the actual connections on your USB breadboard connector might be different as displayed above. GND and VCC might be on different pins !! And I see I mixed up the colors of the wiring. GND should be blue and VCC should be red.

The ESP got enough power to work and at the same time had a connection with my computer so I could monitor data through the Serial Monitor.

If you do this make sure you use a decent 5Volt power supply. You are connecting an external power-supply indirect to the USB port of your computer. If anything fails you are in risk of damaging your computer !! So make absolutely sure that you are using an excellent external power supply, which does not deliver more as 5 volts.

Till next time

Luc Volders

Permanent storage using EEPROM

$
0
0
For an index to all my stories click this line

I suppose this is something every reader of this weblog has ran into. You are making a project and you want to save some values of variables. Why ? Well every time your program restarts it starts with the initial values. But what if you want to continue where you left last time ?

An example is my Simon game. You can find that in the following blog-posts:
https://lucstechblog.blogspot.com/2018/12/simon.html
https://lucstechblog.blogspot.com/2018/12/simon-part-2.html

My girlfriend really likes this game. But it lacks something. It does not remember the high-score. So she wants me to build a new version with a display that shows the current high-score and the overall high-score.
The problem is that the Arduino, Attiny and the ESP microcontrollers erase their ram memory when they power down and restart. Therfore the overall high-score is never remembered.

The solution is to store the value of your variables in permanent memory.
When you do this, you can safely power down your project. Next time when you power it up again the project can read the values back from the permanent memory. This way your high score is stored safe.
You can use this for any kind of data you want to store permanent. Think about highest and lowest temperature readings, the last color settings of an RGB strip etc. etc.

The Arduino processors have a build-in EEPROM (Electrical Erasable Programmable Read Only Memory) and both the ESP8266 and the ESP32 have flash memory. Let's use that.

Arduino and Attiny85 EEPROM



The Arduino and Attiny processors have an internal EEPROM memory of 512 bytes. So they can store 512 values. As each of these 512 memory places is one byte they can each store a value from 0 to 255.
For the sake of this example I am going to show you how to save 10 values in EEPROM memory. Just look at this example program:



// ======================================
// test program for EEPROM write and read
// adapted by Luc Volders
// ======================================

#include <EEPROM.h>

intvalue=0;
inti=0;

voidsetup()
{
Serial.begin(9600);
for(i=1;i<10;i++)
{
EEPROM.write(i,i+10);
delay(100);
}

for(i=1;i<10;i++)
{
value=EEPROM.read(i);
Serial.print(i);
Serial.print("\t");
Serial.print(value,DEC);
Serial.println();
}


}

voidloop()
{
}

I'll explain what is going on.

#include <EEPROM.h>

The first thing you need to do is to import the EEPROM library.

int value = 0;
int i=0;

Two helper variables are defined.

Then the real program is put in the setup. This way it runs only once.

Serial.begin(9600);

The Serial port is activated and we can check what is happening through the serial monitor.

  for (i=1; i<10; i++)
  {
    EEPROM.write(i, i+10);
    delay (100);
  }
 
This is where the magic happens.
The loop counts from 1 to 10. These are the EEPROM bytes where we are going to store our demo values. i is the location in the EEPROM memory where we are storing our values and i+10 is the value we are going to store. You can replace the i+10 value by anything you like as long as the value stays between 0 and 255.

  for (i=1; i<10; i++)
  {
    value = EEPROM.read(i);
    Serial.print(i);
    Serial.print("\t");
    Serial.print(value, DEC);
    Serial.println();
  }

After the values are stored we read them back with EEPROM.read(i). And i is again one of the memory places 1 to 10. The read value is then printed to the serial monitor to see if everything went well.

Now power down your Arduino or Attiny and upload the next program:


// ======================================
// test program for EEPROM read
// adapted by Luc Volders
// ======================================

#include <EEPROM.h>

intvalue=0;
inti=0;

voidsetup()
{
Serial.begin(9600);

for(i=1;i<10;i++)
{
value=EEPROM.read(i);
Serial.print(i);
Serial.print("\t");
Serial.print(value,DEC);
Serial.println();
}
}

voidloop()
{
}

As you can see it is the same program as the previous but I omitted the writing part. So the only thing that happens is that the program reads the EEPROM memory and prints its values to the Serial monitor.



And this is the Serial Monitor output. As you can see even when the Arduino is powered down and a new program is loaded, the values stored in the EEPROM are still preserved.

ESP8266 and ESP32 EEPROM



Both the ESP8266 and the ESP32 do not have any build in EEPROM memory. But they do have flash memory. That is the same memory you are using in your photocam or phone and that does not looses its info when the power is shut down. So let's use that.

Luckily for us the Arduino EEPROM library has been adapted in such a way that it works for the ESP series controllers. We only have to make a minor adjustment in the program.


#include <EEPROM.h>

#define EEPROM_SIZE 100

intvalue=0;
inti=0;

voidsetup()
{
Serial.begin(9600);

EEPROM.begin(EEPROM_SIZE);

for(i=1;i<10;i++)
{
EEPROM.write(i,i+10);
EEPROM.commit();
delay(100);
}


for(i=1;i<10;i++)
{
value=EEPROM.read(i);
Serial.print(i);
Serial.print("\t");
Serial.print(value,DEC);
Serial.println();
}
}

voidloop()
{
}


A short look at the differences from the Arduino program.

#define EEPROM_SIZE 100

For the ESP series we have to define how large the chunk of memory is that we want to put aside as an EEPROM substitute. Here I reserved 100 bytes but you can use as much as 4096 bytes. Quite a lot more as the Arduino allows you.

EEPROM.begin(EEPROM_SIZE);

This line tells the EEPROM library how much memory we want to reserve.

EEPROM.commit();

And this line actually confirms the write to the memory. You NEED to invoke this line after every write to the EEPROM memory.

The rest of the program is the same.

Write limits.

Both the EEPROM memory in the Arduino and the Flash memory in the ESP series have a limited lifespan. You can read as often as you want from the memory but you can write only about 100.000 times before the EEPROM breaks and your Arduino or ESP likely breaks down to.

100.000 times writing boils down to 273 year if you write once a day a value to the EEPROM or Flash memory. If you write a value each hour to the memory the controller will break down after 11 year. Writing every 10 minutes to the EEPROM or Flash memory will bring the lifespan of your controller back to about a year and a half.

Till next time
Have fun

Luc Volders

ESP8266 sending data to Domoticz

$
0
0
For a complete index to all my stories click this text !!

If you have not heard about Domoticz by now it is time you should.




Domoticz is a complete home automation system that is open source and free for you to download. It runs on Apple, Windows, Linux and last but not least Raspberry. You can find the web-page here: http://www.domoticz.com/

My system is running on a Raspberry 2B with some extra hardware called RF-Link. My RF-Link clone an Arduino Mega with a 433Mhz Transmitter and Receiver. This makes it possible for Domoticz to communicate with Klik-Aan-Klik-Uit and other cheap 433 Mhz switches, doorbells, blinds, weatherstations etc.
Domoticz itself communicates with systems like Philips Hue, Sonos, Anslut (Ikea lights), Mi-Light etc etc etc etc. You can find a complete list of brands and devices on the Domoticz Wiki Page:
https://www.domoticz.com/wiki/Hardware

The Domoticz software is controlled from a webpage that can be accessed by your PC and there are Android App's available to control it from your tablet or phone.

You can even make rules like switch the TV on, close the curtains, switch the home-cinema on and dim the lights. So with one button your set for a move evening.

Summarising: with Domoticz you have a complete system to automate your home which will set you back around 60 euro.

I bought some cheap 433 Mhz switches and automated the lights in my hobby room, living room and with christmass I switch on the christmass-tree and all related lamps from anywhere with the App on my phone.

This is all great but I wanted more.

In all the years I am tinkering I build several projects with led-strips, sensors like a rain-sensor, door and window sensors, a thermometer etc. I want them all to be controlled from Domoticz.

Next to that I want to build some special switches. For example a switch with an LDR that tests the light in a room and automatically puts on the lamps when needed. Or a switch that puts a lamp on when someone enters a room. You can do all this with individual switches. But it is neat to have one central place where it all comes together.

As an add-on for Domoticz someone started a project called ESP-Easy ( https://www.letscontrolit.com/ ) that makes it easy to attach sensors to an ESP8266 and connect that to Domoticz. A really neat project so check it out.

However I want to do things myself and presumably you to otherwise you would stop reading from here.

So what I am going to show you here is how a button pressed on the ESP8266 sends a command to Domoticz which then sends a command to a 433Mhz light switch. Great for making remote controls for Domoticz. And next I am going to make a temperature sensor that sends it's data to Domoticz. 


Intermezzo

I am moving away from ESP-Basic. It is no longer maintained nor updated. And there is no ESP32 version available. So I am building most of my new projects in the Arduino IDE (C++). I must admit that writing and develloping programs in ESP-Basic is faster as writing and debugging in C++. There are however a lot of nice sensors and add-ons available now which are not supported in ESP-Basic. So this story will be one of the last ones in which the program is in ESP-Basic.

ESP on screen button as remote for Domoticz

First thing we are going to build is an ESP8266 that creates a webpage on which a button can be clicked that sends information to Domoticz. In my setup I have a 433 Mhz lightswitch that controls a lamp in my hobbyroom which I am going to control this way.









Start with looking in Domoticz at the devices list for the switch you want to control. I wanted to control "Lucs room lampje" which has IDX number 3. We need that number to put in our program.

To control this switch we need to call a Domoticz API. You can find a list off all Domoticz API's here: https://www.domoticz.com/wiki/Domoticz_API/JSON_URL's

On this page look for the entry : Turn a light/switch on
There you will find the required API call:

/json.htm?type=command&param=switchlight&idx=99&switchcmd=On

So what we need to do is to build a webpage with a button on it and when that button is pressed this code is send to Domoticz. And that is easily done with ESP-Basic.

For those of you who have no experience with ESP-Basic I urge you to read this tutorial which will have you up and running in no time:
http://lucstechblog.blogspot.nl/2017/03/back-to-basic-basic-language-on-esp8266.html

And here is the program.



cls
wprint|<h1style="text-align:center;">LucVolders</br>Domoticz</br>Control|
wprint"<br/><br/>"

button"Lamp on",[domoticzon]
wprint"<br/><br/>"
button"Lamp off",[domoticzoff]

wait

[domoticzon]
query="192.168.1.66/json.htm?type=command&"
query=query&"param=switchlight&idx=3&switchcmd=On"
ret=wget(query,8080)
wait

[domoticzoff]
query="192.168.1.66/json.htm?type=command&"
query=query&"param=switchlight&idx=3&switchcmd=Off"
ret=wget(query,8080)
wait

Let's have a look at this.

The program starts with putting some text on the screen and two buttons for ON and OFF.

When one of the buttons is pressed the program jumps to the accompanying routine wich calls the API. As described above the API looks like this:

/json.htm?type=command&param=switchlight&idx=99&switchcmd=On

and that is translated in ESP-Basic in this:

query = "192.168.1.66/json.htm?type=command&"
query = query & "param=switchlight&idx=3&switchcmd=On"
ret = wget(query,8080)

query is the variable in which the data is collected that is going to be send. 192.168.1.66 is the IP number of my Domoticz setup. You have to replce that with your own IP. The rest of the API call is just copied except the IDX number which I altered in the number of my switch: 3

The wget statement sends the API call and puts the answer in the ret variable. You do not need to add this line but if you do not any info that Domoticz send back is displayed on the screen which makes a mess of your screen.

I do not think that it can be programmed in any other language for the ESP more easier.



And this is the result on your computer / phone / tablet's screen.

The buttons Lamp on and Lamp off switches lucs room lampje on or of and that can bee seen in Domoticz and off course by just looking at the lamp.





Temperature Sensor

I also wanted to send some sensor data to Domoticz. So I attached a Dallas DS18B20 temperature sensor to the ESP8266 (NodeMCU board) to see if I could get some readings.

To setup a switch or sensor in Domotics that is not physical attached but gets it's data through wifi you will have to define a virtual switch.


First in Domoticz open the devices tab and create a virtual switch. Give it a name. I choose Virtueel 3 and choose as type Dummy.


Now choose create virtual sensor I gave it as name Test temperature and as sensor type Temperature


At this moment the sensor is already visible in the Temperature Tab of Domoticz although it does not have received any value and therefore the temperature will be 0



Go back to the devices menu (Apparaten in Dutch) and there you can find Virtueel 3 and as you can see that the ID number is 4592

Next step is to build the hardware


My test setup is just a DS18B20 with a pull-up resistor of 4.7K attached to GPIO2 (D4) of a NodeMCU board.

In ESP-Basic I wrote a small test pogram to see if the sensor worked.


cls
wprint|<h1style="text-align:center;">LucVolders</br>Domoticz</br>Thermometer|
wprint"<br/><br/>"
wprint"The temperature is now "&temp(0)

wait

Nothing special. The program just reads temp(0) which is the DS18b20 and puts the value on the screen.

Back to the Domoticz API page on the web:https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s#Create_a_virtual_sensor
Here we can read how the API call looks for reading a sensor.

/json.htm?type=command&param=udevice&idx=IDX&nvalue=0&svalue=TEMP

IDX = id of your device (This number can be found in the devices tab in the column "IDX")
TEMP = Temperature

So we just need to implement that in our ESP-Basic program. Here you go:


cls

timer1000*60*5,[domoticztemp]

wprint|<h1style="text-align:center;">LucVolders</br>Domoticz</br>Thermometer|
wprint"<br/><br/></h1>"
wprint"The temperature is now "
textboxtemptest
wait


[domoticztemp]
temptest=temp(0)
temptest=(int(temptest*10))/10
query="192.168.1.66/json.htm?type=command&"
query=query&"param=udevice&idx=4592&svalue="&temptest
ret=wget(query,8080)
wait

Again very easy to implement.

A timer is setup that every 5 minutes calls the [domoticztemp] routine.

Timer 1000 * 60 * 5 = every 5 minutes

The formula is simple. ESP's timer works in miliseconds. So 1000 = 1 second (1000 miliseconds). 60 Seconds in a minute and that times 5 minutes.

Why the 5 minute routine ? Well Domoticz just displays the sensors reading once in the 5 minutes on it's screen.


And there you go: the temperature is displayed in Domoticz.

Last step: Combine button and Temperature

A NodeMCU or a Wemos D1 have many I/O ports. Why not use them ? So let's combine the button and the temperature programs and include a physical button as well.


Again the hardware setup is easy. I took the temperature setup and added a button that is connected with a pull-up resistor (10k) to D3 of the NodeMCU board.


cls
wprint|<h1style="text-align:center;">LucVolders</br>Domoticz</br>Control<br>AndThermometer|
wprint"<br/><br/>"

but=0

button"Lamp on",[domoticzon]
wprint"<br/><br/>"
button"Lamp off",[domoticzoff]
wprint"<br/><br/>"
wprint"The temperature is now "
textboxtemptest

interruptd3,[change]
timer1000*60*5,[domoticztemp]

wait

[domoticzon]
query="192.168.1.66/json.htm?type=command&"
query=query&"param=switchlight&idx=3&switchcmd=On"
ret=wget(query,8080)
wait

[domoticzoff]
query="192.168.1.66/json.htm?type=command&"
query=query&"param=switchlight&idx=3&switchcmd=Off"
ret=wget(query,8080)
wait

[change]

ifbut=0then
query="192.168.1.66/json.htm?type=command&"
query=query&"param=switchlight&idx=3&switchcmd=On"
ret=wget(query,8080)

else
query="192.168.1.66/json.htm?type=command&"
query=query&"param=switchlight&idx=3&switchcmd=Off"
ret=wget(query,8080)

endif

but=1-but
interruptd3,[change]
wait

[domoticztemp]
temptest=temp(0)
temptest=(int(temptest*10))/10
query="192.168.1.66/json.htm?type=command&"
query=query&"param=udevice&idx=4592&svalue="&temptest
ret=wget(query,8080)
wait


No surprises in the software either. An interrupt tests wether the button has been pressed and jumps to the [change] routine.

but = 1 - but

This line toggles the but value between 0 and 1 for setting the switch ON or OFF.

The rest is the same as in the previous programs.


This is how it looks on the screen of your computer / phone / tablet.

Hey, what's that Luc's Room Temperatuur thing ???


Well remember my "Oh no, not another wifi thermometer." entry in this weblog. If not you can re-read that story here: http://lucstechblog.blogspot.nl/2017/11/oh-no-not-another-wifi-thermometer.html


As you might remember this thermometer not only set's its data on the screen of a webpage but it also sends it's data to Thingspeak. To refresh your memory you can re-read the weblog entry here:
http://lucstechblog.blogspot.nl/2017/11/thingspeak.html

Well that thermometer has been sending it's data also for a long time now to my Domoticz setup.

Here is the altered code for that Thermometer.


tel=0
Timer5000,[start]

wprint"<!DOCTYPE html>"
wprint"<html> <body>"
wprint|<bodystyle="background-color:greenyellow;">|
wprint|<H1><spanstyle="color: red;">|
wprint" A thermometer"
wprint"</H1>"
wprint"</span>"
wprint|<H2><spanstyle="color: blue;">|
wprint"Temperature is now "
textboxtest

a="background-color:greenyellow;"
a=a&"display:block;width:80px;"
a=a&"border-style: hidden;"
a=a&"font-size: 22px;"
a=a&"font-weight: bold;"
a=a&"color: fuchsia ;"
cssidhtmlid(),a
wprint"</span>"
wprint"</H2>"
Wait

[start]

test=temp(0)
test=((int(test*10))/10)
tel=tel+1
iftel=360then
tel=0
gosub[thing]
endif
wait

[thing]
sendthing=str(test)
SENDTS("MY-API-KEY","1",sendthing)

'andtoDomoticz
domoticz="192.168.1.66 /json.htm?type=command&param=udevice&idx=2662&svalue="&test
wget(domoticz,8080)

wait

As you can see the temperature is not only put on a webpage accessible from your computer/phone/tablet but also send to Thingspeak like described in this story:
http://lucstechblog.blogspot.nl/2017/11/thingspeak.html

And now it also sends the data to Domoticz, using the same code as described above with just another IDX.


The chart shows you that the thermometer has been working continuously from july 2017. This shows how reliable the ESP8266 and ESP-Basic is.

As stated in the beginning of this story: I am moving away from ESP-Basic to the Arduino IDE (C++). So in upcoming stories I'll be showing you how to achieve this in C++. So stay tuned.


Till then
have fun

Luc Volders

Installing non-allowed apps on Android

$
0
0
For an index to all my stories click this text

I was doubting wether I would buy an e-reader or a new tablet. My current tablet is on Android 4 and getting so slow that when pressing an icon for opening a program you can wait a loooooonnnnnggggg time before something happens.
Next to that some programs (APPS) are no longer available under the old Android 4 or can not be updated.

I have several uses for a tablet. I use it for reading books and documents I find on the web (mostly technical), as a control station for my Domoticz home automation, and I use it for program- and App-devellopment.

An e-reader can only be used for reading books.

So a new tablet was it going to be.







There are many fancy tablets which will cost a fortune. And I am a cheapskate. So I bought a tablet from Alcatel with a 7-inch screen, a reasonable fast processor, 8Gb storage and 1 Gb ram, USB, Wifi and Bluetooth. Best of all it runs Android 8.1. I added a 64Gb SD-card which was on offer at the local dollar-shop for 7 euro. Now I had a tablet with a lot of memory for a total of 56 Euro !!!!

I started installing all kind of apps which worked flawlessly. And then disaster struck !!!

One of the apps that I use frequently is the IFTTT app. I use it for communication with Google Home and for notifications from my ESP's. I wrote more as 10 stories on IFTTT on this weblog. You can find them in the INDEX PAGE  https://lucstechblog.blogspot.com/p/index-of-my-stories.html

On my tablet I searched for IFTTT in the play store and I could not find it. Now that is very awkward.

At first I thought there was something wrong with IFTTT. So I tested it by giving commands to my Google Home and they worked. Then I started the APP on my phone and that worked to..... IFTTT was fully operational so why did it not show up on my new tablet ??



I used the browser on my PC to access the play store on my PC. I searched for IFTTT and there it was !!



So I logged-in on my PC with my tablets account and password and searched again for IFTTT. And here it came up !! So why not on my tablet ???



There it was: This app is incompatible with your device !!!!

How on earth is that possible. I have plenty of memory on my tablet. A modern processor with quad-core. A reasonable screen and Android 8.1. It should work !!!

I tried the install button om my PC's screen. Maybe I could install it from my PC onto my tablet.



No avail. Install was greyed out and would not operate.

Why ??

Well there are several reasons why you are not allowed to install some apps on your phone or tablet.
Sometimes a developer is not paying attention and defines that an App can only run on Android XXX and later while that is not the case.
A developer can also forget to disable the settings for certain sensors. For example running an acounting package does not need the use of the gyro or compass functions on your phone/tablet. However if the developer forgets to rule these out Google Play thinks you need them for the app and if your phone does not have them then you are not allowed to install the app.
Maybe you are not allowed to use certain apps in your country......

What now ???

Google to the rescue.


Sounds like a paradox. Google prohibits me to install something and I will use Google to search how to avoid their own rules ;)

I know that all Android APPS are first loaded onto your phone/tablet as an APK file and then installed. Maybe I could find the IFTTT APK file somewhere on the web. A google search came up with multiple places on the web where you can get APK files bypassing Google Play. I give you here the links to a few:

APKMirror  https://www.apkmirror.com/
APKPure    https://apkpure.com/
Fdroid     https://f-droid.org/
APK-DL     https://apk-dl.com/
Aptoide    https://www.aptoide.com/

I used APKMirror and will show you how to use that site for getting App's Google withholds you.



So I searched for IFTTT on APKMirror and it came up almost immediate.



From APKMirror I could download the APK file to my computer.

Getting the APK on the tablet

The only thing I had to do now was to transfer the APK to my tablet.

There are two ways to do that.

Install with PC

First thing is to make sure you have Google Drive installed on your tablet and on your PC. A similar service like Dropbox or OneDrive will work alike.

Open Google drive with the browser on your PC and login with your tablets credentials.
Transfer the downloaded APK to Google Drive on your PC.

drive

When the file has been uploaded it will directly be available in Google Drive on your tablet.
So switch to the tablet.

Open Google Drive on your tablet.



Click on the file and download it on your tablet.
It will then be transferred from Drive to the Download folder on your tablet. Open that folder with the Android file-app. Click on the APK file.



Android will give you a warning that this will be an insecure install.



Give permission to proceed.



Now you can install the IFTTT app.

Install with Android.

Actually it is the same as installing the App from your PC. The difference is that you use the browser on your tablet (or phone) and download the APK file directly.
The download will be in the download folder (obvious). Open that folder with the Andoid file-app. Click on the APK file and follow the instructions which are the same as the last steps you can see above.

So there you have it.

This way you can install all kinds of apps on your phone or tablet which are not allowed by Googles Play store.

Caveats and Pitfalls

There is a possibillity that you download a 64 bit app while working on a
Android phone or tablet that has a 32 bit processor. Another problem can be that an app expects certain sensors which are not available in your phone/tablet. These are a few examples that can make an installed app crash.

Despite these caveats this is a great way to try apps which Google does not allow you to install.

Till next time
Have fun

Luc Volders


ESP32 makes Google Assistant talk

$
0
0
For an index to all my stories click this line.

Often when I am strolling around the internet I stumble upon something which I think is usefull or just plain fun. As I have no immediate plans for it I bookmark it for future use. And sometimes I find something which seems so much fun to play around with that I drop everything and start experimenting.

When I stumbled upon an interesting new library for the ESP8266 and ESP32 I immediately wanted to try it. And it is fun!!

I tried to get this working on the ESP8266 and failed miserably. I always got a compilation error indicating that I was missing some libraries. On the ESP32 however it worked flawlessly. Maybe you have more luck. So I'll stick to the ESP32 for this project.

Before I go on I have to give you some background information.

Two year ago I build a Google Home Assistant clone with a Raspberry. This works great but has some flaws. First it can not play music or radiostations as that function is disabled. Second I can not controll it with the Google APP. And lastly I can not alter the language in Dutch. The language part is the least interesting to me as I am confortable with English anyhow.



As soon as it became available in the Netherlands I bought a Google Home mini. First thing I did was making a connection to my Domoticz system. And now my mancave is really something from the future. When I walk into my room I just have to speak out loud the commands: "Hey Google set the hobby room lights on" and "Hey Google play NPO radio 1" and presto the lights turn on and Dutch radio 1 is played on the Google Home Mini.

I believe most of you (and which nerd or geek like me doesn't have one) who are familiar with the Google Assistant series think it is fun to give the Assistant commands and ask it all kind of things like weather forecast, traffic etc. etc.

I can ask Google Assistant all kinds of information it can find on the internet and command it to switch on lights and do other tasks in my home. It is however not possible to have the Assistant SAY anything you want. Well it is do-able by delving deep into the developer options and creating custom actions. But it could not be done in an easy way until now.

And then I found the Google Home Notifier library on the internet. This actually makes the Google Assistent say anything you want when you want !!!

Actually you will need two libraries. The first one is esp8266-google-tss which can be found here: https://github.com/horihiro/esp8266-google-tts 
and the second one is esp8266-google-home-notifier which can be found here:
https://github.com/horihiro/esp8266-google-home-notifier

 


I urge you to install the latest Arduino IDE and then you can find there libraries also in the Libary manager found under the Sketch tab of the IDE.




The first library being esp8266-google-tts takes some text as input and sends it to Google. Google makes an MP3 file from that text.
The second library, esp8266-google-home-notifier, gets the MP3 file and sends it to your Google Home Assistant.

Install both libaries and let's have some fun.

Before the library can send information to your Google home it has to know where to find your Assistant. Please be aware that there are two things to consider. The library can only find an Assistant which is on the same network as the ESP is. And the language of your assistant must be set to english although that can be altered.

How to find your assistant.

There are two ways to find your assistant. Both have to be done on your Android Phone. 




If you have google Assistant installed on your phone swipe to the assistant screen and scroll down till you see the name of the Google Assitant. Mine is called Living Room speaker.





The second way to find your Assistant is to open the Assistant App on your phone and there you can also find the name of your Assistant. Again you can see the name I gave it is Living Room speaker.

With this information you are ready to start programming.

The first program.

Let us start with someting simple. The program will make Google Assistant tell you it is ready for your commands.



#include <WiFi.h>
#include <esp8266-google-home-notifier.h>

constchar*ssid="YOUR ROUTER NAME HERE";
constchar*password="YOUR PASSWORD HERE";

GoogleHomeNotifierghn;

voidsetup()
{
Serial.begin(115200);
Serial.println("");
Serial.print("connecting to Wi-Fi");
WiFi.mode(WIFI_STA);
WiFi.begin(ssid,password);

while(WiFi.status()!=WL_CONNECTED)
{
delay(250);
Serial.print(".");
}
Serial.println("");
Serial.println("connected.");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());

constchardisplayName[]="Living Room speaker";

Serial.println("connecting to Google Home...");
if(ghn.device(displayName,"en")!=true)
{
Serial.println(ghn.getLastError());
return;
}
Serial.print("found Google Home(");
Serial.print(ghn.getIPAddress());
Serial.print(":");
Serial.print(ghn.getPort());
Serial.println(")");

ghn.notify("Hi Luc, I am waiting for your commands");

Serial.println("Done.");
}

voidloop()
{
}


A quick analyse of what is happening in the program.
As you can see everything is happening from within the setup routine. This makes sure the program only runs once.

#include <WiFi.h>
#include <esp8266-google-home-notifier.h>

const char* ssid     = "YOUR ROUTER NAME HERE";
const char* password = "YOUR PASSWORD HERE";

GoogleHomeNotifier ghn;

The above lines start with loading the libraries. We installed two libraries for this program. The esp8266-google-tss library is loaded from within the esp8266-google-home-notifier library. So we do need it but it is not included in our own program the other library takes care of that.

Do not forget to fill in your own routers credentials otherwise the ESP32 can not connect.

The setup starts wit6h connecting to the internet as usually and then it prints the it's IP adress in the Serial Monitor.

  const char displayName[] = "Living Room speaker";

  Serial.println("connecting to Google Home...");
  if (ghn.device(displayName, "en") != true)
  {
    Serial.println(ghn.getLastError());
    return;
  }

This section defines the name of the Google Assistant and looks if it is available, and also checks wether the language is set to English. Fill in exactly your own Assistant's name otherwise nothing will happen.

Sidenote:
The check for English language is important. The TSS library which is called from within the esp8266-google-home-notifier sends an English text to the google service which makes an MP3 from your request. The response would be really akward if the English Assistant tried to pronounce an foreign language text.

  Serial.print("found Google Home(");
  Serial.print(ghn.getIPAddress());
  Serial.print(":");
  Serial.print(ghn.getPort());
  Serial.println(")");

If everything checked positive the information about your Assistants IP adress and port are printed in the Serial Monitor.

ghn.notify("Hi Luc, I am waiting for your commands");

And this is the important line. This will actually have the Assistant speak your text.

That's it for now.
Play with this and let your assistant say whatever you want.

In the next part I'll show you how to have the assistant say some usefull things like sensor information.

Till next time.
Have fun.

Luc Volders

Piezo becomes buzzer

$
0
0
For an index to all my stories click this text

I was experimenting with making some sound and noises with the ESP32.




To get some sound of the ESP32 there are two options. You can use an amplifier with a speaker or a Piezo Buzzer. I attached a Piezo Buzzer which worked just fine.




Few years ago I purchased some Piezo's to be used as a sensor. I started wondering what would happen if I attached one of these instead of a buzzer. I did and nothing happened. No sound came from the bare Piezo.

Then I put it out of the way on a plastic box with the wires still attached and suddenly I heard a sound. I moved the Piezo a bit around and the sound got better.

Obviously the difference between the bare Piezo and the buzzer was the housing. That started me wondering. There is a distinct price difference between the two. The buzzer is much more expensive as the bare Piezo. So how about building my own casing.


I sat behind my computer and designed a casing in Tinkercad. It consists of 2 parts.


The bottom which has a small opening at its side to let the wires out.


And a lid with a small hole so the sound can get out.




And here is the end result.

If you want to print them yourself. Just download the STL files from my Github repositry and go ahead.


https://github.com/Lucvolders/Piezohousing

Have fun and keep safe

Luc Volders

Steady hand game

$
0
0
 For an index to all my stories click this text


In these days of the Corona crisis simple games can help to keep your kids (and yourself) occupied. Therefore I build one. I guess everybode knows this game. There is a track made of wire and there is a loop wich must maneuvered along the track without touching it.





Here is the basic idea. This is a picture from Wikipedia



You can build this with a few electronic parts. You can even build this with just a led and a battery. And you can build it with a ESP8266. Using the latter you can ad leds, 7 segment displays etc. to fancy it up.




Above are a few samples of commercially available versions. Here is my version: 3 strike out !!


I build this with an ESP8266. It can easily be altered for using an Arduino or one of its family members. By exchanging the leds for neopixels and altering the program accordingly you could even use an Attiny85 to make this project.

Breadboard.

 

The setup is simple. 3 leds are attached to D7, D6 and D5. A button is attached to D0. The track wire is connected to GND and the loop wire is connected to D1. If you do have a Piezo Buzzer attach it to D2.

The program

Nothing special in the program. Each time the wires touch a led is lit, and the buzzer sounds. If you touch the wire more as three times your done and nothing further happens till you push the button and the game is reset for the next attempt or contestant.



constintBuzzerPin=4;
constintContactPin=5;
constintButtonPin=16;
constintledpin1=13;
constintledpin2=12;
constintledpin3=14;
intcount;

voidsetup()
{
pinMode(ContactPin,INPUT_PULLUP);
analogWrite(BuzzerPin,0);
pinMode(ledpin1,OUTPUT);
pinMode(ledpin2,OUTPUT);
pinMode(ledpin3,OUTPUT);
digitalWrite(ledpin1,LOW);
digitalWrite(ledpin2,LOW);
digitalWrite(ledpin3,LOW);
count=0;
}

voidloop()
{
if(digitalRead(ContactPin)==0)
{
analogWrite(BuzzerPin,200);
delay(400);
analogWrite(BuzzerPin,0);
if(count<3)
{
count++;
}
}
switch(count)
{
case1:
digitalWrite(ledpin1,HIGH);
break;
case2:
digitalWrite(ledpin2,HIGH);
break;
case3:
digitalWrite(ledpin3,HIGH);
break;
}
if((digitalRead(ButtonPin)==LOW)&&(count==3))
{
digitalWrite(ledpin1,LOW);
digitalWrite(ledpin2,LOW);
digitalWrite(ledpin3,LOW);
count=0;
analogWrite(BuzzerPin,0);
delay(1000);
}
}

If you do not own a buzzer you can easily leave that part out. The program can easily be modified to use a display instead of leds etc.

In real life.

I just used a solid electrical wire for the track and a piece of the same wire for the loop.



Above is my prototype on a breadboard. The track is a wire across the breadboard. The loop is on the left side at the bottom. A coathanger is the best material for the loop and track. Put it on a wooden shelf for sturdiness and experiment with different shapes.

Have fun

Luc Volders
Viewing all 318 articles
Browse latest View live