Out of memory

My latest project is related with home automation. It’s based on Arduino nano as main MCU. As project roadmap has lots of features, I saw that out of memory problem will hit soon. It is few decisions to make:

  1. Optimize code. Yes – it can save few bytes, but what I will do after new feature request will arrive?
  2. Find bigger MCU. Bigger brother in Arduino family is Arduino Mega. It has lots of memory, and lots of I/O pins. Perfect solution, but size is lots bigger. It can be catastrophic, when you make tiny device.
  3. Migrate to STM family. It’s interesting approach, as they have fast and big in memory MCU’s. Lots of devices are based on STM chips, so maybe It’s time to learn something new.

STM is interesting approach, BUT … there is not so many info in Internet about STM programing, as it is more industrial chip. Arduino community is much bigger and more active, so solution to save time is using Arduino. Browsing internet I found one company, which are making Arduino Mega PRO which is smaller and fits embedded devices:

I ordered few of these boards from aliexpress, and they come quite quickly, about in 2 weeks. Wery well packed, and production quality is perfect. Arduino code succesfuly uploaded from the first time, and everything works normal. Comparision between Arduino Mega and Mega PRO:

Now I have lots of memory, and lots of I/O pins, so can resume my project. See you soon.

Weekend project – learning KiCad

Everyone who likes diy electronics, needs to make custom boards. Long time ago, I was tried to make Nixie tube clock, and designed it with Eagle. Today I wanted to learn something different, and choosed KiCad, as opensource software. One key feature, it can easy export PCB to gerber files for manufacturing PCB in online making companies. Long story short, here are few screenshots after long day learning new features:

  1. custom board in 3d view:

2. Same board with attached 3d arduino nano:

3. Back view:

4. Some schematics:

Al in all, tool is not easy for startup, some steps are unclear, and needs online tutorials to go through. But after half day, it becomes easy and full of features, which helps to design custom PCB boards. So if you are searching opensource tool for PCB design, it worth to try KiCad.

I will try to finish this design soon, and order some boards from online makers. I hope that next time we will review finished board, and see it working 🙂

Weekend project – fixing Arduino ethernet shield

Few days ago I received message from Post, that new toy are waiting in Post office. I decided to try wired connection with Arduino, as Chinese are making cheap clones. For those who did not know how this device looks, here are image from internet:

This shield is compatible with Arduino Uno and Mega. As I have spare Arduino Mega, connected shield to Mega, connected Ethernet cable directly to laptop. After few minutes Arduino connected to network and started to answer ICMP (ping) packets. All seemed perfect, while connection was directly to PC network card. My router did not had spare network ports to try, so in next day I bought network switch. With smile in my face, I connected Ethernet shield to brand new switch, and was excited to try mqtt communication with Mosquito mqtt broker.

After Arduino was powered ON – nothing happened. Shield is not accessible … first idea – lets try to get IP address from DHCP. Recompiled program to use DHCP, opened serial console for debug, and very strange issue – no IP from DHCP. All leds are blinking, but no connectivity. After that, Ethernet cables was changed, tried different switch ports – no results. It’s time to dig internet for solution, and after deep searching, solution was found in Arduino forum. Happily, I’m not the one who tried cheap Chinese clones, and this time clones have wrong components inside, shields did not work with switches. Thanks to one guy in forum, who suggested workaround: solder additional resistors, to fix incorrect resistance in board. Here is step by step guide to fix issue:

  1. identify if board have wrong component. In this foto you can see selected component, if there are written 511, you have possible issue.

2. Solder additional 100 oms resistors, to fix issue. Here are pads where you need additional resistors:

Here are results:

I did not had 100 oms resistors, so tried to solder 220 oms. They also worked like a charm.

3. Working “patched” Ethernet shield:

Please note, that this fix you should take on your own risk, and I’m not responsible, if you you will have issues reproducing this fix on your own board. But if you succeed, please post comment here 🙂

Experiments with smart house equipment

As usual men, I have 3 goals: plant a tree, grow a son, ant build the house. First one is done, second one is in progress, so it’s time to start third one. I’m little bit IT guy, so thinking about smart house. Digging around the internet, I found cheap smart switches, whose may help to improve house characteristics, ant make it smarter. Here they are:

I ordered some of them, to test build quality, and possibility to integrate with central smart house control system. From first view, they looks futuristic, have touch interface, works on wifi, let’s try to integrate with home automation system.

By default, these switches can be controlled over smart phone app, or directly by touch button. App is created by manufacturer, and has no possibility to integrate with home automation system. Also, communication works over internet with third party server, which stands over the ocean, so it’s not the best idea to trust this design. So, lets improve this design, with opensource solutions. Browsing github, I found project, which are ideal for my requirements: https://github.com/arendst/Sonoff-Tasmota

Main features required: works ower wifi, can be controlled over MQTT broker, and best of the best: can be flashed/upgraded over OTA. Few weeks ago, when I discovered this project, firmware upgrade procedure was (or I thought that it was) complicated, as additional programming pins should be soldered. This is not big issue, as these devices has lot of space to solder programming pins, but later I had big success, finding that these devices can be upgraded over OTA: over-the-air upgrade. So let’s start to hack this device:

First of all, I need to prepare laptop for this task:

  1. install python 3.5 in windows 10 (yes, I know, windows is not the best option for home use, but this is another topic) 🙂
  2. download magic sonOTA script: https://github.com/mirko/SonOTA
  3. install required libraries for sonOTA: pip3 install –user -r requirements.txt
  4. start the magic stript: python sonota.py, read instructions in console and let the magic happen.

In short, this script will push opensource firmware over OEM upgrade channel. Detailed instruction are written in hithub, so I don’t rewrite it here. After upgrade, smart switch was connected to home wifi network, got IP address and publishes web page, where you can configure various settings, as mqtt server address, smart switch hostname and other fancy stuff.

In my lab, I have Raspberry, running Openhab as smart home automation system, ant Mosquitto as MQTT server. So the last step, is to integrate smart switch to the smart home. As this smart switch has MQTT support, this task is easy. first of all, I created new item in Openhab:

Switch jungiklis <light> {mqtt=”>[openhab:Light/sonoff/cmnd/power:command:ON:1],>[openhab:Light/sonoff/cmnd/power:command:OFF:0],<[openhab:Light/sonoff/POWER:state:ON:ON],<[openhab:Light/sonoff/POWER:state:OFF:OFF]”}

Second, include this item to sitemap:

Frame label=”Apsvietimas”{
Switch item=jungiklis label=”Apšvietimas” mappings=[ON=”Įjungtas”, OFF=”Išjungtas”]

Vualia, now I can control room light with touch button, or over my phone via Openhab, or can create some automation script, and let smart home control lights automatically, is it not fancy? 🙂


At last interesting DIY project found

I always wanted to find interesting DIY project, where I can program, solder, and research some technology, by result creating useful stuff. Some time ago I found some cheap LORA modules, which allows create wireless communication between devices. Arduino also are good sandbox, which allows easy join some devices together, using tons of Arduino libraries available. So here are the main components for first recipe:

  1. Arduino nano:It’s one of smallest Arduinos available on the market, but still powerful enough to create some useful stuff, especially for the first project. Also, these modules are very cheap in China market.
  2. Oled display:These displays are also useful for printing useful information to the end user, or developer for source debug purposes. I2C communication allows connect these modules easily to Arduino board.
  3. LORA modules:I choosed Ra-01 module. These modules are small enough, allowing small product creation, using popular SX1278 chip inside, 100 mW transmit power, theoretically providing range up to 10 KM, it’s more then enough creating first communication to remote device. And one of the best option, there are Arduino library available for these chips. In the market exists Ra-01 baby sister: Ra-02 which have small antenna connector:At the moment I do not have this type of antennas, so choose first version of the board, but in the future there is posibility to upgrade with ease.

With these components, my goal is to create two independent Arduino boards, both sending each other some information, and display this information in the oled screen. After that, we will see how these components works together, and what usefull stuff we can create, maybe some Smart House device, who knows. See you soon 🙂