Saturday, March 24, 2018

RGB-Strip Control over Wifi Part 1

You can find an index to all my stories by clicking this line

In a previous story I wrote on this web-log in April 2015 I described how to control a RGB ledstrip with your Android Phone Using Bluetooth. You can find that story by clicking here.

The problem with Bluetooth is it's short range. About 10 meter if you are lucky. The new Blue-tooth variations (BLE) have a longer range and even use less power. However the Arduino modules for this are not so commonly available and there are a lot of smart-phones around that do not support this yet.
Wifi however is something that all smart-phones and tablets have available. And using wifi you can even control things from your desktop computer or notebook.

So let's modify the  ledstrip controller for using it with an ESP-8266 so we can control it over wifi.

Basic

For this project I am writing the software in ESP-Basic.
In a previous story on this web-log I showed you how to install ESP-Basic and how to use it. I also presented you some basic (pun intended) programs.

Before we start modifying the led-strip controller I will show you how to control a strip of Neopixels in ESP-Basic using sliders. This will demonstrate how easy it is to control Neopixels with ESP-Basic and how easy it is to make a webpage that contains sliders that control the colors of the Neopixels. Something no other language can do in just a few lines of code.

NodeMCU




ESP-Basic has one (f)law: Neopixels have to be attached to GPIO15 which is also called D8 on NodeMCU modules. So we can not use an ESP-01 module for this project.
Considering the price difference between the NodeMCU and an ESP-01, keeping in mind that you will need a voltage regulator and additional electronics for the ESP-01, the NodeMCU is not a bad choice at all.

And we can use the NodeMCU with Neopixels for some othher projects that I will present shortly.

Neopixels

For those not familiar with Neopixels I'll give a short description.
Neopixels are officially called WS2812. The name Neopixels comes from Lady Ada. But what are they. Well they are RGB leds with a difference. They have a Power and Ground lead and a data-in and data-out lead. So you can daisychain them by connecting the data-in from the Neopixel to the  data-out of the previous Neopixel. Next to that each Neopixel has a chip incorporated that simply knows where the Neopixel is in the chain.

You can find an extensive write-up with demo's and how to solder in the story you will find by clicking here.

Let's start with the hardware.

As discussed above please first read the intro-story about the Neopixels.






The hardware is as you can see straightforward. The Neopixels are daisy-chained through a 330 Ohm resistor to D8 of the NodeMCU and they get their power from the 5 Volt line from the NodeMCU. A large capacitor stabilises the power supply.

That's all.

The Basic program.



wprint |<h1 style="text-align:center;">Luc Volders</br>RGB-STRIP</br>CONTROL|  
wprint "<br/><br/>"  
   
slider r, 0, 255  
cssid htmlid(),"background-color: red"  
textbox r  
wprint "<br/><br/>"  
   
slider g, 0, 255  
cssid htmlid(),"background-color: green"  
textbox g  
wprint "<br/><br/>"  
   
slider b, 0, 255  
cssid htmlid(),"background-color: blue"  
textbox b  
wprint "<br/><br/>"  
   
button "<h2>Set</h2>", [set]  
wprint "<br/></h1>"  
wait  
   
[set]  
neo.stripcolor(0,6,r,g,b)  
wait  

Just look at the program and you can see how easy it is. The wprint command prints to the webpage.

The slider g, 0, 255 defines a slider wich gives a variable called g and has a range of 0 to 255.

cssid htmlid(),"background-color: red" is HTML code which gives the slider it's color on the web-page.

button "<h2>Set</h2>", [set] Draws a button on the screen, gives it it's name and makes sure the program jumps to the set routine when the button ism pressed.

And the last line neo.stripcolor(0,6,r,g,b) sets the Neopixel chain in the chosen color. In this example the chain has 7 Neopixels (0 to 6) and the colors are set by the r,g and b variables that we got from the sliders.

And that's all.
A complete web-page with a header, sliders and a button that controls a strip of Neopixels in just 20 lines of code. It could even have been done in less lines but then the page would not have it's fancy looks.

The Basic program puts several HTML codes on the webpage. If you have no knowledge on HTML programming I advise you tale a look at the W3SCHOOLS webpage where yoiu can find a complete course on HTML. The site also has courses on Javascript, CSS and XML.


How to use the program.



First copy the code and open a new file in ESP-Basic. Paste the code in and save it.


Now you just have to run the program and your screen will look like the picture above.

Move the sliders to any position you like and push the set button and the color of the neopixels will change instantly.

The program will work on your computer (as you can see above) but will also run on your Android Phone provided that you have Firefox installed (which is recommended anyway).

On Windows and on Android you will see next to or below the sliders a field in which the RGB values are presented.



You can alter them with the sliders or just type in the desired values.

That's it.

In an upcoming story I will show you how to adjust the program and hardware to control a 'normal' ledstrip with the sliders.

The only thing left here is to present you the source code which you can copy and paste from this page or download at my Github repositry.

https://github.com/Lucvolders/RGB-Strip-Control-with-ESP

 

UPDATE !!!!

I have altered the code in such a way that when you change the sliders the color off the Neopixel chain will alter immediately. 
To achive this you just have to add the following line of code as the first line in the program:

timer 500,[set]

So in the new code on Github I have altered tthe SET button to end the program.

Till next time
Have fun

Luc Volders

Friday, March 16, 2018

Google Assistant on your Smart Phone

I can not believe it is already almost a year ago since I wrote my story about my homemade Google Assistant. As you maybe remember I build my own Google Assistant with a Raspberry Pi and used it to control the lights in my home. The trick was that the Assistant send commands to IFTTT and IFTTT used webhooks to send commands to an ESP8266. You can re-read that story here:
http://lucstechblog.blogspot.nl/2017/05/google-home-and-esp8266.html

I have experimented a lot with Google Assistant since that time and it is now connected to several ESP's and to my Domoticz home controller.




However in the mean time I have treated myself to a new Phone. It is a Nokia 5. Nokia abandonned Microsoft and is on its own again building great phones like they used to in the old days. Equipped with Android, a large screen (5.2 inch gorilla glass), lots of memory, a reasonably well camera, a large battery and equipped with every possible sensor you can imagine: GPS, WIFI, Bluetooth, Gyro. Next to that it came with Android 7 and is already upgraded to Android 8 !!! And the best part is that it is dead cheap for such a great piece of equipment.

And there is a bonus. Google has activated Google Assistant on the smart phones. You will have to set the default language on your phone to English to achieve that. Just open the Google APP and OK Google will be upgraded to Google Assistant.

All the fun parts are there. The easter eggs, the jokes and everything the normal Assistant can do.

On my phone I have a different Google account as I have on my PC at home. I like to keep these seperated. However I was curious wether the Assistant on my phone could perform the same tricks as my Home Assistant could.

So I opened a new IFTTT account by logging into IFTTT with my phone and my Google account. Next I copied my IFTTT receipes from my home account to my IFTTT account on my phone. The easiest way to do this is to open IFTTT on your PC's browser and log in with your main account. Next open another browser window and log in with the Phone's account. That way you can easily copy recipes from one account to another. You still have to retype them though. But you can just copy and paste the fields.


Nothing was altered on the ESP side of the software so you can use the hardware setup and software without alteration from the story on the Assistant:
http://lucstechblog.blogspot.nl/2017/05/google-home-and-esp8266.html
 

When done. Just say OK Google and give the commands and presto !!!







As you can see the Google Assistant on the phone not only listens to spoken commands and answers verbally but it also copies the spoken text's on your phone's screen.




 

Here is the video showing how it works. Unfortunately something went wrong with the sound but you can see what is happening. The lamp in the hobby room is switched on and off and the led connected to the ESP826 representing the living room light is also switched on and off.

The great part of this is that I now have a stationary Assistant in my hobby room to devellop all kind of things and a mobile assistant to activate everything even from outside my home.

This is FUN !!!!

Try it for yourself. And if you do not have a modern smart phone. Treat yourself to one.

Till Next time

Luc Volders

Saturday, March 3, 2018

Beware of Powerbanks with an ESP8266

For an index of all my stories click this text



During several years I have collected a bunch of powerbanks varying in strength. The grey one and the pink one can supply 2 Amps. The black one can supply 4400 Mah that is no less as 4.4 Amps. I even have a bigger one of 6 Amps which I am using to power an experimental wireless car. Normally however I use them as an extra power supply for my phone.

A few weeks ago I was working on a project using an ESP01 which was going to be a kind of alarm system. The idea was to put the ESP in Deepsleep (more about that in another story) which saves power. Combining this with a power bank would make the project last for a long time on this power source.

Did it work ??? Read on !!!

So what I experienced was that things worked but just for half a minute or so and then the power bank shut down !!!

As long as the ESP was operating in normal mode everything worked fine. But as soon as Deepsleep was activated the powerbank would shut down after a short time. 


It took me a while to figure out what was going on.
The cause is simple.

When the ESP enters Deepsleep mode the power consumption is minimal. In fact it is so low that the Powerbank does not notice. Or perhaps it has a treshold and the ESP is consuming far less then the tresh-hold. Therefore the powerbank shuts down.

Back to normal batteries !!!

Till next time
Have fun

Luc Volders