If you find issues with your python version not finding a compatible circuit python version, include --break-system-packages at the end. (It wont break anything today, but don't get used to it...)
Use a site like pinout.xyz to find a suitable wiring configuration.
You're ready to do some tests before making your final move to the PCB.
Script config
You can try Adafruit's demo script. Just make sure that you choose the right display and update any changes to the ping assignment (use IO numbers/names rather than physical pin numbers):
# Configuration for CS and DC pins (adjust to your wiring):
cs_pin = digitalio.DigitalInOut(board.CE0)
dc_pin = digitalio.DigitalInOut(board.D24)
reset_pin = digitalio.DigitalInOut(board.D25)
# Setup SPI bus using hardware SPI:
spi = board.SPI()
disp = ssd1351.SSD1351(spi, rotation=270, # 1.5" SSD1351
cs=cs_pin,
dc=dc_pin,
rst=reset_pin,
baudrate=BAUDRATE
)
PAL is a simplified version of my python home assistant that I’m running in the DFRobot UNIHIKER which I’m releasing as free open-source.
This is just a demonstration for voice-recognition command-triggering simplicity using python and hopefully will serve as a guide for your own assistant.
Current version: v0.1.0
Content
Features
Current version includes the following:
Voice recognition: using open-source SpeechRecognition python library, returns an array of all the recognised audio strings.
Weather forecast: using World Meteorological Organization API data, provides today's weather and the forecast for the 3 coming days. Includes WMO weather icons.
Local temperature: reads local BMP-280 temperature sensor to provide a room temperature indicator.
IoT HTTP commands: basic workflow to control IoT smart home devices using HTTP commands. Currently turns ON and OFF a Shelly2.5 smart switch.
Power-save mode: controls brightness to lower power consumption.
Connection manager: regularly checks wifi and pings to the internet to restore connection when it's lost.
PAL voice samples: cloned voice of PAL from "The Mitchells vs. The Machines" using the AI voice model CoquiAI-TTS v2.
UNIHIKER buttons: button A enables a simple menu (this is thought to enable a more complex menu in the future).
Touchscreen controls: restore brightness (center), switch program (left) and close program (right), when touching different areas of the screen.
Installation
Install dependencies for voice recognition: pip install SpeechRecognition
Some theme configuration has been enabled by allowing to choose between different eyes as a background image.
Use the variables "eyesA" and "eyesB" specify one of the following values to change the background image expression of PAL:
"happy"
"angry"
"surprised"
"sad"
"happy""angry""surprised""sad"
"eyesA" is used as the default background and "eyesB" will be used as a transition when voice recognition is activated and PAL is talking.
The default value for "eyesA" is "surprised" and it will change to "happy" when a command is recognized.
PAL voice
Use the sample audio file "PAL_full" below (also in the github repo in /mp3) as a reference audio for CoquiAI-TTS v2 voice cloning and produce your personalized voices:
Adding your own commands to PAL is simple using the "comandos" function.
Every audio recognized by SpeechRecognition is sent as a string to the "comandos" function, which then filters the content and triggers one or another matching command.
Just define all the possible strings that could be recognized to trigger your command (note that sometimes SpeechRecognition provides wrong or inaccurate transcriptions).
Then define the command that is triggered if the string is matched.
def comandos(msg):
# LAMP ON
if any(keyword in msg for keyword in ["turn on the lamp", "turn the lights on","turn the light on", "turn on the light", "turn on the lights"]):
turnLAMP("on")
os.system("aplay '/root/upload/PAL/mp3/Turn_ON_lights.wav'")
Activation keyword
You can customize the keywords or strings that will activate command functions. If any of the keywords in the list is recognized, the whole sentence is sent to the "comandos" function to find any specific command to be triggered.
For the case of PAL v0.1, these are the keywords that activate it (90% it's Paypal):
At the moment, PAL v0.1.0 only includes compatibility with Shelly2.5 for demonstration purposes.
Use variables lampBrand, lampChannel and lampIP to suit your Shelly2.5 configuration.
This is just as an example to show how different devices could be configured. These variables should be used to change the particularities of the HTTP command that is sent to different IoT devices.
More devices will be added in future releases, like Shelly1, ShellyDimmer, Sonoff D1, etc.
Power save mode
Power saving reduces the brightness of the device in order to reduce the power consumption of the UNIHIKER. This is done using the system command "brightness".
Change "ps_mode" variable to enable ("1") or disable ("0") the power-save mode.
Room temperature
Change "room_temp" variable to enable ("1") or disable ("0") the local temperature reading module. This requires a BMP-280 sensor to be installed using the I2C connector.
Check this other post for details on sensor installation:
Below are a few examples of queries and replies from PAL:
"Hey PAL, turn on the lights!""Hey PAL, turn the lights off"
Future releases (To-Do list)
I will be developing these features in my personal assistant, and will be updating the open-source release every now and then. Get in touch via github if you have special interest in any of them:
Advanced menu: allow configuration and manually triggering commands.
IoT devices: include all Shelly and Sonoff HTTP API commands.
Time query: requires cloning all number combinations...
I keep experimenting with the UNIHIKER board by DFRobot and it’s incredibly fast to make things work in it. Today I’ll show you how to set up on-screen real-time temperature display in two minutes using a BMP-280 module and zero programming.
Content
Prerrequisites
Here's the trick. I was expecting you already had a few things working before starting the countdown:
Download and install Mind+, DFRobot's IDE for UNIHIKER. On Linux, it is a .deb file which does take a while to install: https://mindplus.cc/download-en.html
Solder a BMP-280 temperature and pressure module and connect it to the I2C cable. You might need to bend your pins slightly as the connector seems to be 1mm nano JST.
In Mind+, go to the Blocks editor and open the Extensions menu.
Go to the pinpong tab and select the pinpong module (which enables interaction with the UNIHIKER pinout) and the BMP-280 module extension, for interaction with the temperature module.
Go back to the Blocks editor and start building your code block. Just navigate through the different sections on the left hand side and drag all you need below the Python program start block:
pinpong - initialize board.
bmp280 - initialize module at standard address 0x76.
control - forever block (to introduce a while True loop).
unihiker - add objects to the display. I firstly add a filled rectangle object to clear previous text, then add a text object. Specify X,Y coordinates where every object will be displayed on the screen and its color.
bmp280 - read temperature property. Drag this inside the text field of the text object.
python - (optional) add a print to show the data on the terminal. I included all other sensor values.
control - add a wait object and wait for 1 second before next loop. All of it should look something like this (click to enlarge)
Launch
And that's all your program done, without any programming! Press RUN above and see how it loads and displays in your UNIHIKER screen. Touch the sensor with your finger to see how values change with the increase in temperature.
Wasn't that only 2 minutes? Let me know via Twitter ; )
The small and efficient form factor of the UNIHIKER makes it really easy to craft a case for it.
For my smart home asssistant I was looking for an android-like style, and the DFRobot logo is perfect for the UNIHIKER, making tribute to their developers.
Content
Github Repo
I've released a github repository where I will be open-sourcing all the model files and people can contribute with their own, so feel free to create a pull request and share your designs!
Today I’m bringing you the second chance that I’ll give Shelly. My first Shelly Dimmer blew up for excess temperature inside a connection box, but another Shelly 2.5 controlling two lights is holding fine, also fitted in the wall.
Maybe the difference is the extra 5ºC that they withstand, so I’m going to fit a wall plug with switch and scheduler using a tiny Shelly 1, and just hope it survives.
Apart from the tiny size, Shelly are easy to configure, so we’ll also see how to control them locally via the HTTP API.
Content
Requirements
My goal is to enable a wall plug that I can control and schedule via WIFI, in my case, to manage the electrical water heater. This is what I'll use:
Shelly 1.
Two wire electric cable (line and neutral).
Male plug.
Female plug socket.
Assembling material for a case (3D printer, plywood, etc).
Shelly 1Electric cableMale plugFemale plug socket (front)Female plug socket (back)Assembly support printed in 3D
Electric connection
Let's look at Shelly's user manual and see how we need to make the connections:
The idea for this standard schematic is to connect Shelly 1 to a light bulb and its switch, where every symbol means the following:
L: line
N: neutral
SW: switch
I: input
O: output
As I want to enable a plug socket, the schematic will vary slightly, as I will not be using any switch and I can connect the input directly to the line. On the other hand, and for I reason I ignore, there is no cabling inside the connection box, so I bring the electric line from another plug using the cable... In the end, it all ends like this:
TIP! I'd say that I confused the cable color norm, but it is not important in this case as its a closed circuit and it will work anyways.
Assembly
You might see that I made a small 3D support to guide the cabling, as well as a lid to cover the void around the socket. Modelling every part in 3D, with real measures, helps to distribute the space properly and ensure that your solution fits:
I'll leave here the 3D .stl models ready to send to your slider software.
Finally, this is how it all looks crafted in place. It's not the perfect fit, but it does the job I needed.
Internet connection
Let's now see how to bring the Shelly 1 to life and control it locally.
Opposite to Sonoff, Shelly makes it much easier and you just need to follow the user manual.
Power Shelly 1 using the male plug.
This will activate an AP (Access Point) or Wi-Fi network with an SSID looking like "shelly1-01A3B4". Connect to this Wi-Fi network using a smartphone or PC.
Once connected, use a web browser to access the IP at 192.168.33.1 and it will take you to Shelly's web interface for device configuration.
Once in, you must config the device (inside Internet & Security menu) so that it automatically connects to your local Wi-Fi network, as well as it is recommended to restrict access with username and password.
We're all set to communicate with Shelly 1 locally.
Shelly HTTP API usage
To use the command of the HTTP API you must know the device IP in your local network.
Find IP in the router
You can access the network map in your router, usually from the address http://192.168.1.1
The address and the password should be in some sticker in your router. Then you'll see your device with a name like shelly1-XXXXXXXXXXXX:
Find IP using nmap
In a terminal you can use the tool nmap to scan your local network.
Download it if not done yet: sudo apt-get update sudo apt-get install nmap
Scan your network (using sudo you'll get the MAC address, which is useful as the IP could change when restarting the router) sudo nmap -v -sn 192.168.1.0/241.0/24
Send HTTP requests to the device
Shelly's HTTP API is well documented in their website:
The value 0 in the URL matches te number of the relay or internal switch in the Shelly. In this case there is only one, but in the case of Shelly 2.5 you have two relays, so you can call them individually changing this value.
In this case, the URL defines the following schedule rule parameters:
HHMM: hour and minute that activate the rule
0123456: days of the week when the rule is active
on/off: status that the rule triggers
This way, to schedule the on and off of the device (except during weekends), you could send a request like this one:
curl -X GET http://192.168.1.XX/settings/relay/0?schedule_rules=2300-01234-on,0700-01234-off
Obviously you can also configure the schedule rules from the web interface, or just check the commands worked:
And that would cover all of it. Jump off and fill your house with tiny Shellys completely customizable. Any questions or comments on Twitter 🐦 please! (though given what's going on with the X thing, who knows how long I'll last...)
I had a Shelly Dimmer inside a plug box in the wall, but one good day it stopped working (probably because of high temperatures, as it stands up to 35ºC). Looking for an alternative, I found Sonoff had released their equivalent for 1/3 the price of Shelly.
But in the end, cheap turns expensive, as it is much more complicated to configure than Shelly Dimmer and it has a bigger size.
After many tests, and given the poor documentation, here I explain how to configure Sonoff D1 Dimmer to use the local API without depending on the e-weLink app.
Additionally, given its size, you wont find much space for it in your connection boxes, so I’ll give you the idea to craft an external connection expansor.
The previous schematic more or less complies with European norm:
Line (positive): black, brown or grey (red in this case...)
Neutral (negative): blue.
Shelly Dimmer is much more compact and fits easily in a connection box. But not in this case, so I will connect it externally using an extension lead, and I will later detail a simple case for its assembly.
TIP! If you're not experienced in electricity, you should review quite a bit and move forward with caution. It's not nice to have a shock with the domestic network. If you do the connection externally this way you won't be in much danger.
For the moment we can now make it work.
Internet connection
This is the complicated bit, as with so much casing, apparently there was no place for the usual pushbutton to power on/off and restore the device.
If you're lucky, your Sonoff wont be preconfigured and you might be able to connect to it on the first attempt. If it's preconfigured, probably to check its operation in another network, the device is no longer accessible even with the e-weLink app, unless you are in the network where it was configured.
To detect it, you must restore to default settings and for this you have two options:
Restore using e-weLink app from the network where it was configured (very unlikely you have access to it).
Restore using Sonoff RM-433 remote controller (you'll end up buying this extra accessory).
Pairing Sonoff RM-433 remote controller
In the end, the cheap D1 price has doubled with the need to buy the RM-433 remote controller, but the price is still not mad. Here is its manual:
The first thing to do is to pair the controller with the D1:
Connect the D1 to a socket.
Hold button 7 for some 5 seconds, until you hear a beep (this removes the previous radio-frequency assignment).
Unplug and plug the D1 to get it restarted.
Press any button on the controller so it's assigned to the D1.
You'll hear another beep and the controller is now paired and can be used to control the D1.
Restore WIFI network
Now you need to restore the network assigned to the D1.
Hold button 8 for some 5 seconds, or basically, until the led starts blinking this way:
Breathing mode. Two fast blinks, one slow blink.
You removed the previous network. Now set it to pairing mode.
Again, hold button 8 for some 5 seconds, or until the led starts blinking continuously:
Pairing mode. Constant blinking.
This way, the device starts a WIFI Access Point (WIFI AP) with a name in the form ITEAD-XXXXXXXXXX.
Pairing with e-weLink
From here, if you want the easy route, just download the e-weLink app and press the quick pairing button. You'll then have your D1 accessible from this app.
Pairing in DIY mode
But I want the complicated way and enable DIY mode to access the device network and control it using commands from the HTTP API in a web app.
We need to find the WIFI network named ITEAD-XXXXXXXXXX set up by the device and connect to it using the password 12345678.
Now open a web browser and access this address http://10.10.7.1 where you'll find the following screens.
Introduce the name (SSID) and password of your WIFI network, and the device is now linked to it.
Assembly
Before getting into the detail of the HTTP API, I'll show you a 3D printed case design to avoid the cables and connections being completely exposed.
It consists of two PLA pieces (base and top) which can be screwed together and which you can download from this server:
To use the command of the HTTP API you must know the device IP in your local network.
Find IP in the router
You can access the network map in your router, usually from the address http://192.168.1.1
The address and the password should be in some sticker in your router. Then you'll see your device with a name like ESP-XXXX which derives from the WIFI module it holds (I already renamed it here):
Find IP using nmap
In a terminal you can use the tool nmap to scan your local network.
Download it if not done yet: sudo apt-get update sudo apt-get install nmap
Scan your network (using sudo you'll get the MAC address, which is useful as the IP could change when restarting the router) sudo nmap -v -sn 192.168.1.0/24
Send HTTP requests to the D1
Sonoff's D1 HTTP API is documented in their website:
In order to communicate with the device, you need to send HTTP requests using some software like Postman or using curl or wget in a terminal.
The request is sent to the device IP, to the default port 8081, and we also have to include the device id in the request body (this id matches the XXXXXXXXXX coding in the WIFI network name ITEAD-XXXXXXXXXX).
Let's see some use cases with curl and Postman.
Device information
http://[ip]:[port]/zeroconf/info
curl
curl -X POST 'http://192.168.1.34:8081/zeroconf/info' --data-raw '{"deviceid": "XXXXXXXXXX","data": {}}'
curl -X POST 'http://192.168.1.34:8081/zeroconf/switch' --data-raw '{"deviceid": "XXXXXXXXXX","data": {"switch":"on"}}'
Postman
Response
{
"seq": 9,
"error": 0
}
Brightness adjustment
http://[ip]:[port]/zeroconf/dimmable
curl
curl -X POST 'http://192.168.1.34:8081/zeroconf/dimmable' --data-raw '{"deviceid": "XXXXXXXXXX","data": {"switch":"on","brightness":50,"mode":0,"brightmin":0,"brightmax":100}}'
Postman
Response
{
"seq": 14,
"error": 0
}
Now you're ready to program your own app and control your D1 to your like in a completely private way. I hope this was useful, but if you find any doubts or comments, don't hesitate to drop them on Twitter 🐦!
After lots of comings and goings, trials, redesigns, burnts, cuts and some minor explosions, finally I can bring a smart desktop clock I have been working on for the last 2 years. Making a detailed tutorial can be even longer and tedious, so I hope these traces can help make your own. I warn you this takes a lot of time and practice, and can’t be done carelessly…
Content
What's Temps-i 7?
Let's break down its name:
Temps mean time in the Valencia dialect,
i for internet, where it gets the time,
7 for the display, which uses 7 segments for every digit.
These three concepts define this compact desktop clock, with WIFI connectivity, temperature sensor and good autonomy.
Let's see how it's made!
Components
First, let's see the recipe ingredients and what each one does:
Sparkfun ESP32-Thing board >>Top performance microcontroller with WIFI and Bluetooth connectivity thanks to the ESP32 integrated chip, ideal for IoT projects.
4 digits 7 segments red color display. >>Shows time and temperature.
BMP-280 module. >>Temperature and barometric pressure compact digital sensor.
100 Ohm resistors >>Needed to reduce display current, without lowering brightness excessively (admits up to 1k Ohm, but leds would be hardly visible with daylight).
PCB with custom circuit. >>Simplifies display and resistors connectiont to the microcontroller.
1000mAh 3.7v LiPo battery >>Ensures an autonomy up to 48 hours without external voltage.
Jumper cables. >>For additional connections of external modules.
Push button >>Used to switch the program on display.
Electronic design
It's very important to study the electronic components being used, read all the specifications and prototype with all precautions before we start soldering like crazy.
Component selection
The components listed earlier are not a mere coincidence or copied from elsewhere. They're the most successful trial of many others and meets the project needs:
The 4 digit display shows exactly what I'm after: the time. If I can also use it to show temperature, that's fine. But a better quality display, like LCD, would be unnecessarily demanding, and autonomy is another key requirement.
The microcontroller includes internet connectivity, as well as enough computing capacity. It also has sufficient in/out pins to control the display without a gpio expansor. Some other options I've tried:
More compact microcontrollers: Teensy 4, Digispark, SparkFun Pro Micro. They need a GPIO expansor (like PCF8574) and/or a WIFI module (like ESP-01). This also involves too many more connections.
Microcontrollers integrating WIFI and sufficient I/O, like NodeMCU ESP8266. Got out-dated and lacks processing capacity as the counter delayed almost 4 seconds every minute.
Prototyping electronic circuit
Having researched and obtained the components, connect them in a prototype board (protoboard) to test their operation.
In my case, after different pin combinations, the most organised way is the following:
ESP32-Thing
Component
VBAT
LiPo +
3V3
BMP-280 3V3
GND
LiPo - BMP GND BMP SD0 Push -
GPIO21
BMP SDA
GPIO04
BMP SCL
GPIO32
Push +
GPIO17
Display Digit 1
GPIO23
Display Digit 2
GPIO19
Display Digit 3
GPIO25
Display Digit 4
GPIO15
Display Segment A
GPIO22
Display Segment B
GPIO27
Display Segment C
GPIO12
Display Segment D
GPIO13
Display Segment E
GPIO18
Display Segment F
GPIO26
Display Segment G
GPIO14
Display Segment P (dot)
Pinout schematic
Once the prototype is achieved, you should save it in a schematic diagram using EDA software (electronic design automation) like Kicad, where you can also generate a PCB design that can be sent for manufacturing. Otherwise, you can always save the schematic in paper, as you wont remember where every cable was going in a couple months time...
Kicad is a bit tricky and it's good to practice with simpler projects. Despite this, it's quite manageable for medium users as it basically consists of searching and choosing symbols for our components and connect their pins accordingly to specifications.
To avoid messing the sketch up with cables, I used names in every connection, which is also valid in Kicad. Also, you'll see that the ESP32-Thing is made up of two 20x pin headers, as I didn't find a working symbol and didn't have time to design one properly. What really matters is that the design is working and coherent with reality.
Kicad shematic
Next step is to assign footprints that are realistic for each symbol, so then we can design a printed circuit board that we can order (usually in China) for 15€ / 5 boards.
You don't need to go crazy on this, specially if you're not experienced. I only need to make soldering connections simpler, as in this case you need about 90 of them but keeping a compact design.
PCB design in KicadPCB 3D viewerOrdered PCBs
Clock programming
Most microcontrollers, like the ESP32-Thing, are compatible with the Arduino IDE, which makes it simpler to connect the board to a PC and load a clock program.
Before starting, it's important to make a list of tasks and functions that we want to include in the program and modify it as we code. This way you can try different functions separately and debug every step to find errors quickly. In my case, and after many trials, the program will consist of the following:
Define libraries and variables.
Configure pins.
Connect WiFi.
Get date via SNTP.
Disconnect and turn off WiFi (saves battery).
Convert date into digits.
Show digits on display.
Start timer.
Start reading program change pin.
Change program on pushbutton activation.
Read sensors.
Show temperature on display.
Update time after timer ending (every minute).
Restart timer.
I don't want to spend too long on the code, and it's also not the most tidy I have, but here it is for anyone who wants to copy it, and also on github:
Notice you'll need these additional libraries installed using the Arduino IDE:
esp32 board manager by Espressif
WiFiMulti library
Adafruit_BMP280 library
(the rest of the libraries derive from these ones)
You should constantly try the performance of the code during prototyping so you can change any pin assignment in case of any malfunctioning. If it's all soldered and something fails, it will be really hard to find and solve the error, if it's from a connection.
Assembly
Soldering
Once the code is checked and the PCB is designed, you can start soldering with caution, as a wrong movement can damage your modules or produce errors in the program.
BMP-280 soldered to boardEsp32-Thing soldered to boardDisplay soldered to boardResistors soldered to board
Case design
Having it all soldered you'll have a better idea of the final volume of the device. I measure it all with precision using a digital caliper to make a 3D model of it.
Blender 3D model of all components in their final position
This way you can now design a case around the model so you can craft it using a 3D printer. You could also use other types of assembling materials like plywood or metal.
I usually craft two pieces (one as a base and another one as a cover) so they can be screwed together. I also include different voids to allow for the connection of the USB cable, to add the program switch button and to add a rotary support to hold the clock in a slot in the television.
I will also use white PLA in one piece and grey in the other to bring more life to the design, ending it all like this:
And that's it. I hope you liked it and find it useful. Now you can get your own WIFI clock crafted! Any doubt about this clock can be dropped on Twitter! 🐦