Something new

Do you have questions about writing plugins or scripts in Python? Meet the coders here.

Something new

Postby kgschlosser » Thu Dec 15, 2016 9:17 pm

Ok all you Pythonites here is something really cool

If you don't know what an esp8266 is.
It's a 80 MHz (overclockable to 160) RISC processor with 36k of ram and typically 512 k storage but has a rhetorical max of 16Meg. it's a wireless N 2.4 GHz card also with a full TCP stack. It also has gpio pins for reading signal as well as sending. You can use one of these to turn lights on and off or as a. Window sensor for a alarm. But it also has the ability to communicate with other devices via the wifi. Or serial, i2c and spi.

But the development is this. Someone has up and made a Python 3 interperter to run. On one of these things

https://docs.micropython.org/en/latest/ ... intro.html

Best part is it will run code you send to it from a website that it hosts no need for compiling.

And the esp is really cheap 1.50 to 2.50 USD if ordered online.

I am going to go nuts with these things for next Christmas and have EG as the controller for my Xmas lights and I am going to use apa102 individually addressable LEDs. Gonna be Awesome.
If you like the work I have been doing then feel free to Image
User avatar
kgschlosser
Site Admin
 
Posts: 2338
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Something new

Postby kgschlosser » Thu Dec 15, 2016 9:23 pm

I am going to make up a plugin. That will take care of getting the interperter onto the controller but will also take the programming out of doing simple tasks with it like changing states of a pin. Or getting the temperature from a sensor connected to it. And i will set up any communications needed to have it trigger events in EG.

This is going to be awesome.
If you like the work I have been doing then feel free to Image
User avatar
kgschlosser
Site Admin
 
Posts: 2338
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Something new

Postby eirik226 » Fri Dec 16, 2016 3:53 pm

I can just google this but you seem to have a good grasp on this stuff.

Does this need anything else to run? Or if I understand correctly, can you buy 10 of these and 10 sensors, put them together and you'll receive the data?
eirik226
Experienced User
 
Posts: 111
Joined: Wed Nov 07, 2012 5:22 pm

Re: Something new

Postby kgschlosser » Fri Dec 16, 2016 4:24 pm

there is code that you will have to key up for the sensor. but the code is very simple to write up and pass into the esp. that's the awesome thing about it.

so say you get a DHT11. which is a digital Humidity and Temperature sensor.
there is already a built in library for the code for DHT sensors.

you can use the code for the network event sender with some minor alterations and the built in library for the DHT11. set the code up to connect to a specific access point send the code over to the ESP via a web page and presto it starts creating events in EG.

it's really really easy to do. and really easy to make a software change to the ESP without having to move it and connect it to a PC via a wire. you can copy and paste the new code into you web browser and the ESP will run it.

you can use one esp to be a "home automation module" if you will.

I will give you a really quick breakdown

ESP8266 (breakout board style easier to work with) 4.00 USD
PIR sensor (motion sensor) 3.00 USD
Light sensor 0.25 USD
Thermistor (Temp Sensor) 0.25 USD
IR Receiver 0.25 USD
IR Transmitter (with amplifier) 3.00 USD


OK so here you go.
if you have your house thermostat connected to EG

you have the motion sensor. so it knows when you are in a room. and if you are in there for a while you can have it turn the TV on via the IR transmitter
the ir receiver would be if you wanted to do something in some other portion of the home. because if you have one of these in each room you would be able to transmit IR in any room.

the light sensor is to know how bright it is outside. (put this in a window) works with the temp sensor
checking the room temp. this will work hand in hand with the light sensor to be able to judge adjusting the temp. so during the summer if you are getting full sun on that portion of the house you will probably want the AC in that room kicked up a bit if you are in it. and at night during the winter. you will want it to kick up the Heat
if you are not home (using EGIGeoZone to pass the information to EG that you aren't) the PIR sensor becomes an alarm and if something is in there when it's not supposed to be have EG send you an e-mail to your text messaging service on your phone. so now you will have a tripped alarm notification as a text message.

and the thing is this whole setup would be able the size of a wallet

and super CHEAP!!!

cost of these items if purchased from various manufacturers

PIR sensor. 100 USD
alarm monitoring company monthly bill 40 USD
temp sensor 60 USD
wifi Itach blaster 120 USD

i am seeing an enormous price difference, not to mention you will have boxes all of the place if you go the second route
and having to make something up to handle communicating with all the various pieces
If you like the work I have been doing then feel free to Image
User avatar
kgschlosser
Site Admin
 
Posts: 2338
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Something new

Postby eirik226 » Fri Dec 16, 2016 4:38 pm

You'd have to buy 1 ESP8266 per sensor, right?

But this sounds awesome, i'm ordering a few right away!
eirik226
Experienced User
 
Posts: 111
Joined: Wed Nov 07, 2012 5:22 pm

Re: Something new

Postby kgschlosser » Fri Dec 16, 2016 7:46 pm

I believe the ESP has 7 GPIO pins. I know at least 5.
Each one of the above mentioned "sensors" only use 1 pin each

But you can also add a pin expander which will take 2 of the pins and turn it into something like 14 if you needed to.
and you can keep on doing this in a daisy chain fashion.
This is really unneeded due to the cost. the ESP is cheaper. and it also doesn't overload the CPU or the memory. so if 7 isn't enough. you go and get another ESP. and if for whatever reason the 2 need to communicate directly with one another. you can set one as an Access Point. and the other can connect to it get what it needs and then connect back to the network that EG is on.
If you like the work I have been doing then feel free to Image
User avatar
kgschlosser
Site Admin
 
Posts: 2338
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Something new

Postby kgschlosser » Fri Dec 16, 2016 8:01 pm

order 1. get it from adafruit. the reason i suggest here is because it has alot of added things. like if you accidentally hook up the power and ground to it backwards it won't toss up a puff of smoke (contrary to popular belief if you collect the smoke and put it back in the thing will still not work). but also since most sensors and things of that nature are 5.0 volt and the ESP is 3.3 volt. it has all the shifting set up so you don't have to worry about making one or buying one it is already built in. but the biggest thing is that it has a power supply built in to step down 5 volt to 3.3 so you won't have to go out and buy a 20 dollar power supply. all ya have to use is a USB cell phone charger. and a cable you have kicking around

https://www.adafruit.com/product/2471

It's 10.00 USD on this site. but the format of the chip makes it easy to work with.

you will also need an FTDI USB to TTL Serial adapter. I recommend you get one that does 3.3volt and 5.0volt you only need one of these and it's for writing the initial firmware to it and can be used when you get other modules. or even need to communicate with something like a TV over serial.

https://www.adafruit.com/product/284

and you will also need to have a soldering iron and solder. you will have to attach the pins to it. recommendation. is to get a bread board kit with jumpers and also get some extra pins and a blank dev board for refining your skills on soldering pins on instead of possibly ruining an ESP
If you like the work I have been doing then feel free to Image
User avatar
kgschlosser
Site Admin
 
Posts: 2338
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Something new

Postby pearbear » Fri Dec 16, 2016 8:41 pm

eirik226 wrote:Does this need anything else to run?

You also need to have a power supply for each unit. You can run them off batteries but the WiFi radio uses a lot of power so you won't get very good battery life so best to use a wall wart if possible. If you're moving beyond just experimenting you will want an enclosure to protect it. My current favorite flavor of ESP8266 board is the WeMos D1 Mini, which has the USB circuitry and voltage regulator and reversed polarity protection diode but still in a very compact package and super cheap on Aliexpress or eBay($2.60/ea USD with free shipping last time I checked). Sometimes the shipping from China can be very slow so might be worth paying more for something located in your country if you're anxious to get it soon. The D1 Mini have "shields" for various sensors or other components to make it pretty easy, though you will need to solder the headers but that's easy enough.
pearbear
Experienced User
 
Posts: 150
Joined: Mon Apr 02, 2012 10:28 pm

Re: Something new

Postby kgschlosser » Fri Dec 16, 2016 9:24 pm

@ pearbear

see what I have discovered is. if you buy the cheaper ones from ali or wherever. they are going to be 3.3 V then you will have to buy a 30 dollar wall wart for it. and you really don't want to buy a cheaper one then that because of EMI and AC bounce. the ESP's really do not like it.

so for 10. you get a breadboard compatible one with a step down built on board that can handle up to 6V has all of the level shifters already built on board. and you can use a simple USB cell phone charger. because it outputs 5 volts and it's clean and they are far less expensive point in fact most people have a drawer full of things like that.

so 32.50 + 10.00 level shifters there are a bunch of them so 42.50 per module.

or 20 for the ESP and a cell phone charger with USB cable

I am thinking the latter is the way to go.

Now if i was concerned about reliability i would do a wall wart only because a 24/7 draw of 500 ma the cell phone charger isn't going to last as long as the wall wart but on the flip side they are so common.
If you like the work I have been doing then feel free to Image
User avatar
kgschlosser
Site Admin
 
Posts: 2338
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Something new

Postby kgschlosser » Fri Dec 16, 2016 9:27 pm

the other thing is I do know that the micropython will run on the adafruit ones. don't know about the wemos
If you like the work I have been doing then feel free to Image
User avatar
kgschlosser
Site Admin
 
Posts: 2338
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Something new

Postby kgschlosser » Fri Dec 16, 2016 9:30 pm

Oh and with the micropython there is a way to get the things to go into power save mode. and come back out and continue running your code. where typically it restarts your program. so battery life would be extended an enormous amount.
If you like the work I have been doing then feel free to Image
User avatar
kgschlosser
Site Admin
 
Posts: 2338
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Something new

Postby pearbear » Fri Dec 16, 2016 10:38 pm

kgschlosser wrote:see what I have discovered is. if you buy the cheaper ones from ali or wherever. they are going to be 3.3 V

The WeMos D1 Mini has a voltage regulator onboard so you can power it via 5V USB or the 5V pin. I'd have to look at the specs for the voltage regulator to be sure but I'd guess it can handle up to 6V, though 5V will be more efficient. Of course the I/O is 3.3V but same with the Adafruit so if you need level shifters you'll need them whichever board you choose, there's no difference there(other than the UART and reset but since the D1 Mini has the USB onboard you usually wouldn't need level shifters on those pins anyways.

kgschlosser wrote:Now if i was concerned about reliability i would do a wall wart only because a 24/7 draw of 500 ma the cell phone charger isn't going to last as long as the wall wart but on the flip side they are so common.

I use the terms wall wart and phone charger interchangeably. It's easiest to power the D1 Mini using a power supply with a USB micro connector, which probably means phone charger.

kgschlosser wrote:the other thing is I do know that the micropython will run on the adafruit ones. don't know about the wemos

It will definitely run on the D1 Mini. There are different ESP8266 modules available but the only differences is the antenna(PCB, chip, or SMA) and the size of the flash chip, the actual microcontroller is always the same. They both use PCB antennas so there's no real difference there. For MicroPython you definitely want a decent amount of flash but both boards have the 4MB flash chip so there's no difference there either.

Now don't get me wrong, I'm not trying to say there's no difference between the Adafruit Huzzah and the WeMos D1 Mini. The cheap D1 Minis you get on Aliexpress/eBay are actually clones so you can't really expect much in the way of tech support. I have found that eBay sellers are very good about sending replacements/refunds for lost or DOA orders because they don't want bad feedback, Aliexpress sellers not so much. You definitely can't expect any hand-holding from those sellers when you're trying to figure out how to use the thing, most of them probably have no experience with the ESP8266, it's just a widget to sell for them. However, there is good community support available for the ESP8266 on the ESP8266.com forum(or Arduino forum if you're using the Arduino core) and they don't care where you bought your board from. There may be a higher quality standard of manufacturing and parts at Adafruit. For a beginner it may worth the extra cost to avoid any extra complications but keep in mind that you will also have to buy the USB-serial breakout/cable($14.75/$17.95 from Adafruit) for the Adafruit Huzzah and that part is built in on the D1 Mini. Of course you don't need to buy one of those for every Huzzah and you can get them much cheaper elsewhere. Even with the built in USB functionality the D1 Mini is still smaller than the Huzzah. D1 Mini doesn't have the mounting holes but my use of these boards is as a module plugged into female headers on another circuit board, which has the mounting holes. The USB jack on the D1 Mini is useful not only for firmware updates but also for connecting a power supply. With the Huzzah you only have the holes on the board to connect the power supply, making it a bit more difficult to connect a wall wart or phone charger.

kgschlosser wrote:Oh and with the micropython there is a way to get the things to go into power save mode. and come back out and continue running your code. where typically it restarts your program. so battery life would be extended an enormous amount.

True, and you can also do that via the Arduino core, NodeMCU, etc. but if you want the ESP8266 to be listening for communications you can't do that so it depends on your application and whether you want to be able to do OTA firmware updates without physically accessing the device..
pearbear
Experienced User
 
Posts: 150
Joined: Mon Apr 02, 2012 10:28 pm

Re: Something new

Postby kgschlosser » Sat Dec 17, 2016 12:46 am

pearbear wrote:It will definitely run on the D1 Mini. There are different ESP8266 modules available but the only differences is the antenna(PCB, chip, or SMA) and the size of the flash chip, the actual microcontroller is always the same. They both use PCB antennas so there's no real difference there. For MicroPython you definitely want a decent amount of flash but both boards have the 4MB flash chip so there's no difference there either.


https://www.adafruit.com/products/3269

there is one right there and it states it will not run Node or micropython and you can't even flash it with the arduino IDE

there can be some kind of a difference between them. i do not know if this is because of the board it's self. or some sort of different ESP but it shows there are some that will not work.

does the wemo have the built in voltage step down??? I am curious to know because if has the USB. also is the USB an FTDI to TTL? is it used for flashing? does the wemo have the built in level shifters?. if it does it is the much better buy. and i would be curious to know if it will run the micropython. and as far as "flashing" the thing. with micropython you aren't actually flashing it unless you want the code you are puttin onto it to reside in the flash memory. because python doesn't compile the code and runs it directly it reside in the part of the flash that isn't firmware related. but you can add your code to the core and then access it as a package and that would require the unit being flashed but if there is a PIR hooked up to it. that would wake it up. so all you would have to do is walk into the room. and then go back to your computer and copy and paste the python code into your browser.

I haven't had the chance to mess around with it yet. I have to replace the mainboard in my server this evening and if that goes nice and smooth (god i hope so) then i will mess with it.
If you like the work I have been doing then feel free to Image
User avatar
kgschlosser
Site Admin
 
Posts: 2338
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Something new

Postby pearbear » Sat Dec 17, 2016 1:43 am

kgschlosser wrote:
pearbear wrote:It will definitely run on the D1 Mini. There are different ESP8266 modules available but the only differences is the antenna(PCB, chip, or SMA) and the size of the flash chip, the actual microcontroller is always the same. They both use PCB antennas so there's no real difference there. For MicroPython you definitely want a decent amount of flash but both boards have the 4MB flash chip so there's no difference there either.


https://www.adafruit.com/products/3269

there is one right there and it states it will not run Node or micropython and you can't even flash it with the arduino IDE

there can be some kind of a difference between them. i do not know if this is because of the board it's self. or some sort of different ESP but it shows there are some that will not work.

That's the new ESP32, not ESP8266. It's pretty nice, you should check it out. I'm guessing the ESP32 will eventually make the ESP8266 obsolete but the price is still higher and the last I heard the availability was on and off but I'm sure that will all change soon. A quick search shows that there is a micropython port for esp32. There is also an Arduino core for it and LUA so that Adafruit description is outdated. Of course support for a new chip does take time to get stable so you would likely have less of a "beta" experience using the ESP8266 but some people like to play around with the new and shiny and there should be certainly low hanging fruit left to make valuable contributions to those projects without too much effort.

kgschlosser wrote:does the wemo have the built in voltage step down?

Yes it has a voltage regulator

kgschlosser wrote:is the USB an FTDI to TTL?

It's the CH340, just like you'll find in most of the Arduino clones. You just need to install the driver and it works great with none of the worries about the FTDI driver bricking counterfeit chips.

kgschlosser wrote:is it used for flashing?

Yes, it's connected to the UART pins and the voltage pins. EDIT: and the reset pin also for auto-reset before flashing.

kgschlosser wrote:does the wemo have the built in level shifters?

The Adafruit HUZZAH ESP8266 Breakout only has level shifters on the UART and reset pin. The Wemos D1 mini handles this via the CH340, which can run at either 5v or 3.3V. Since the D1 Mini powers the CH340 at 3.3V the output levels are also 3.3V. All other IO pins on either board are not level shifted so you may need to be careful about connecting them to 5V devices. There is actually a lot of disagreement about whether the ESP8266 is 5V tolerant and there is apparently even a statement from the president of the company that created the ESP8266, Espressif stating that it is 5V tolerant:
https://www.facebook.com/groups/1499045113679103/permalink/1731855033731442/?comment_id=1732364133680532
but I'd rather to play it safe and not connect the ESP8266 inputs to 5V levels.

kgschlosser wrote:if it does it is the much better buy. and i would be curious to know if it will run the micropython

Email me your address and I'll mail you one tomorrow to play around with so you don't have to wait for the China shipping. First search result I found is a post on the micropython forum from one of the micropython contributors, who has also written a bunch of libraries for it:
https://forum.micropython.org/viewtopic.php?t=1870
Successfully installed v1.8 on my WeMos D1 Mini.


kgschlosser wrote:as far as "flashing" the thing. with micropython you aren't actually flashing it unless you want the code you are puttin onto it to reside in the flash memory. because python doesn't compile the code and runs it directly it reside in the part of the flash that isn't firmware related. but you can add your code to the core and then access it as a package and that would require the unit being flashed but if there is a PIR hooked up to it. that would wake it up. so all you would have to do is walk into the room. and then go back to your computer and copy and paste the python code into your browser.

You do have to flash Micropython to the ESP8266 initially unless you find a board that has it pre-installed, which I haven't seen yet and you will need to repeat the process if you want to update to a new Micropython version, though it sounds like OTA updates are something they're working on. But yeah, you wouldn't have to reflash to upload your python code as you have to when using the Arduino core. The downside is there's a lot of overhead for the python interpreter. My preference is to stick with C++ but for EventGhost people who are Python wizards I'm sure Micropython would be awesome and the ESP8266 has enough flash and a fast enough processor that you can get away running less efficient code and still be able to do a lot.
pearbear
Experienced User
 
Posts: 150
Joined: Mon Apr 02, 2012 10:28 pm

Re: Something new

Postby kgschlosser » Tue Dec 20, 2016 6:05 am

well see that is the beautiful thing about python. if you need the speed. you can still code in C++

:-D
If you like the work I have been doing then feel free to Image
User avatar
kgschlosser
Site Admin
 
Posts: 2338
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Next

Return to Coding Corner

Who is online

Users browsing this forum: No registered users and 3 guests