Constant Current 300mA Led drive with a battery charger

Li-ion battery chargers use the CC/CV algorithm. CC means Constant Current and CV is Constant Voltage. When a battery is under charge, the device supplies a constant current until a threshold voltage is reached (typical 4.2V), then applies a Constant Voltage. When the charging current drops below the 10% of the set value, the battery is disconnected (float). I tried to use a battery charger to light a white led at 300mA constant current. The trick is that the led (obviously) does not recharge, so the charger remains continuously in CC mode, with the current set as programmed.

The prototype working with a power white led

The prototype lights a power white led (click to enlarge)

I built the circuit on a proto board, using a self made adapter for the smd IC TP4056. Note that this IC has a metal pad on the bottom side, for thermal dissipation. I soldered a wire under the chip before placing it onto the adapter. The schematic is very simple:

Hand-made schematic. The IC accepts max 8V in input. I used 6.2V supply (click to enlarge)

Hand-made schematic. The IC accepts from 4 to 8V as input. I used a 6Volts battery for the test (click to enlarge)

Detail of the prototype board :

The prototype. Note the wire that comes out from the bottom side of the IC (click to enlarge)

The prototype. Note the wire that comes out from the bottom side of the IC and the metallic stripe used for thermal dissipation (click to enlarge)

Now it’s time to test. I used a trimmer for setting the value of charging current. For 300mA the value must be 4K Ohm. If you don’t want to use a trimmer, such non-standard value can be obtained paralleling two resistors: 10K and 6.8K (the result is 4.04K). The image below shows the current measured with a multimeter.

Led ON, driven with 300mA current (click to enlarge)

Led ON, driven with 300mA current (click to enlarge)

Note the 1N5819 diode at the charger output. This is important. The white led I used has a typical Forward Voltage of 3.42 Volts and if you connect it directly to the BAT signal of the IC (pin 5) the charge does not start. You will have a current that is the 10% of your settings, so about 30mA. The IC “starts” if there is a voltage near 3.7V ; the diode 1N5819 has about 0.35V voltage drop at 300mA, so 3.42V of led plus 0.35V of diode makes 3.77V and the circuit start “charging” at 300mA. I also tested one commercial board I purchased some time ago on ebay. I just modified the charge set resistor and added the diode at the output. Please note that if you set higher currents, the IC will be hot. I don’t recommend current values higher than 300mA, without any thermal dissipation. This IC is not made to be a led driver. For professional results, use one made for that purpose.

test with a commercial board (click to enlarge)

test with a commercial board (click to enlarge)

Here is a table for values of resistor to set a specific current and the position of such resistor on the circuit.

Change the circled resistor to modify the charging current (click to enlarge)

Change the circled resistor to modify the charging current (click to enlarge)

Single 3.7V Li-ion cell power back-up for Raspberry Pi

 I have a small application continuously running on Raspberry Pi board. Sometimes, in my country, we have (short time) mains power failures. In such situation, my Raspberry board, powered by the wall adapter, turns off immediatly, without any attention for open files, transmissions in act, etcetera. This is really a problem. I decided to use some materials purchased in the past on ebay to realize a small power back-up unit, using a single Li-ion cell. First of all, you need for a battery charger circuit, to maintain the back-up battery fully charged. The battery is 3.7V typical, and 4.2V when fully charged, but the Raspberry Pi board wants 5V supply, so we need for a Step-Up circuit. As third element, we need for a switch that disconnects the load from battery when mains supply is present, ’cause the charger can’t see the real battery level if you connect a load while charging. I suggest to read this document released from Microchip: AN1149.

circuit-view

The prototype (click to enlarge)

The charger can be easily found on ebay searching for “1A Li-ion battery charger”. It’s based on well known chip named TP4056. In the picture there is a circle indicating Rchg. The component circled is the charge resistor. The value of such resistor sets the charging current. In the original circuit, the value of Rchg was 1K2 (smd mark 122) that sets 1A charge current. I removed such resistor and placed a new one with value 3K3 (smd mark 332). With this resistor, the charging current will be about 370 mA. I don’t want to charge the battery at higher rate for two reasons: the first is the capacity of the cell (I used a small one), the second is that the wall adapter MUST have enough current to drive the charger AND the Raspberry Pi board. In the next picture you can see three different situations:

Charge / discharge steps (click to enlarge)

Charge / discharge steps (click to enlarge)

Starting from the left, you can see the circuit connected to the wall adapter and the battery charging (red led ON), then the battery fully charged (blue led ON), then the wall adapter has been removed (both leds OFF). Note that the multimeter measures 5.13V in all cases.

The step-up module can be found with a search on ebay, looking for step-up regulator with variable voltage (mine is based on recent XL6009 chip). The XL6009 regulator is rated for Vin_min = 5V, but I tested that works with 3.5V. For best operative conditions, look for a step-up module that mounts an LM2577S-ADJ chip, that is rated for Vin_min = 3.5V. Note that you must trim the variable resistor to have 5V output. Please, connect a 1K resistor as load to the output when setting the Vout, ’cause there is a capacitor that remains charged when you turn the trimmer decreasing the output voltage. After setting, remove the load resistor.

The switch element cannot be purchased on ebay (sorry) and you must build it by yourself. I started from the circuit proposed in the Microchip’s application note and just modified something. For the P-channel mosfet, I used a free sample received from NXP: the PMV48XP. This SOT23 mosfet is very small (look at the picture “The SWITCH”), but it’s really powerful. I used two 1N5819 Schottky diodes (not one) to reduce the voltage drop and increase the current. The circuit is very simple:

The Switch (click to enlarge)

And finally, look at the next picture. The circuit is connected to my Raspberry Pi board. In the animation you can see that the board doesn’t turn off when the wall adapter is disconnected. The time of back-up depends from the capacity of the cell that you use. Remember that the current drawn from the battery (when wall adaptor is disconnected) is the nominal current of the Raspberry Pi board multiplied for the efficiency of the step-up in converting from Vbat  to 5V.

Conenctin and disconnecting the wall adapter (click to enlarge and animate)

Connecting and disconnecting the wall adapter (click to enlarge and animate)

Test report
Test conditions: battery fully charged, Raspberry Pi running Raspbian Wheezy and connected to HDMI monitor and to USB interface for RF keyboard and mouse. No other applications running, just the desktop and the default services. I disconnected the wall adapter exactly at 17:17 .
Test results: the battery discharged from 4.2V to 3.7V (about 20% of residual charge) at 18:18, so in about 1 hour.

Switch relays On/Off with WhatsApp messages

I recently installed the famous messaging application “WhatsApp” on my smartphone. After a while, I decided to create a device that can remotely switch two relays On or Off using messages sent through WhatsApp. Obviously, you must have two active accounts (and two smartphones) for remotely control the relays. In this description we call them the transmitter and the receiver. This device needs for a specific circuit (the relays board) and for a special Android application that works together with WhatsApp on receiver smartphone. Let’s start with the description of the circuit (the hardware), then the Android application (the software) will follow.

The hardware

The hardware is based on PIC12F635 microcontroller from Microchip. It’s a small 8 pin device. In the picture you can see the prototype, realized on a 50x70mm proto board. The smd micro has been placed on small adapter (the red one on the left).

The working prototype

The working prototype

The schematic is relatively simple. We have the micro, a DTMF tone decoder (MT8870), a couple of relays and a switching regulator from 12V to 5V. That’s all.

Schematic diagram; click to enlarge

Schematic diagram; click to enlarge

If you want a more readable copy, download the PDF file at this link. Please note the switching regulator module KIS-3R33S. I purchased a lot of (used) modules on ebay, at very low price. The problem is that the module is rated for 3.3V -3A max output, but I need for 5V out, so I modified the module removing a couple of components: one zener diode and one 51K resistor. It’s a very simple operation, please look at the picture:

The switchin regulator and the parts that must be removed.

The switching regulator and the parts that must be removed. (click to enlarge)

This switching regulator is needed only if you want to have an USB output that can recharge the smartphone that you use as receiver. In other cases, you can simply use a 5V linear regulator capable of 100-200 mA output current. A reduced (easy) schematic will be like this: (please, note that also ICSP section has been removed, that means you must program the micro off-board).

A reduced (easy) version of the schematic (click to enlarge)

A reduced (easy) version of the schematic (click to enlarge)

A pdf version of this schematic can be downloaded at this link.

The circuit detects a sequence of four DTMF tones. The first three tones are “the activation key” and are fixed to ‘1’, ‘3’, ‘7’, while the fourth tone is “the command” and can have the values: ‘2’ for R1-ON R2-OFF, ‘5’ for R1-OFF R2-ON, ‘6’ for R1-ON R2-ON and finally ‘8’ for R1-OFF R2-OFF. Once built up, the circuit can be tested with every device capable of playing MP3 files. The test files 1372.mp3, 1375.mp3,1376.mp3 and 1378.mp3 can be downloaded as a zip file from this link. Connect a stereo jack from the circuit to the player and play one at a time the 4 files. The relays will follow the combination presented as DTMF tones.

To make hardware work, you must program the PIC micro with the .hex file that can be downloaded from this link (updated version:150409 – changed red LED behaviour and implemented timeout after valid key received). The Configuration Bits for the PIC12F635 in this application is shown here:

The configuration word for PIC12F635

The configuration word for PIC12F635 (click to enlarge)

Using the ICD2 programmer under MPLAB, you can receive a warning like this:

ICD2 warning (click to enlarge)

ICD2 warning (click to enlarge)

On my prototype the device is correctly programmed if you click the “OK” button.

The software

The WhatsApp (I will use WA abbreviation from now on) protocol is proprietary and I don’t want to hack the received text messages; so… how to decode a command for relays activation ? I have seen on my smartphone there is a folder named WhatsApp/Media/WhatsApp Images. When you receive an image as attachment to a message sent via WA, a copy of that image is saved on this folder. So, my way to control the relays is simply to poll that directory to see if a new IMG file is present, then I load that file in an imagebox of my Android App and analyze the contents in order to decode the relays command; after that the image is renamed (next polling doesn’t find it again). This way to operate is non-intrusive and co-operative with WA application.

The transmitter doesn’t need any additional application; you just need to store the command images on a folder that’s visible for WA when you try to send an image as attachment ( I use the Downloads folder on main storage). The commands are four (all the combinations of two relays) and are small and simple images:

The images that will be used as attachments for sending commands

The images that will be used as attachments for sending commands

The lower part is for the user (human readable), while the upper part will be read by the Android application. Note that the left two bits are the complement of the right two, this is just to have a validity check while analyzing the image. You can download all the files zipped at this link. Finally, when you want to activate a relay on the receiver, simply send from transmitter a WA empty message with one of the previous command images as attachment.

The receiver is a little bit more complicated. You must download, first of all, a special ringtone, that is the “key” to assign the receiver to a specific transmitter. After downloading the ringtone from this link (right button mouse click to download the ringtone if your browser tries to play it directly), you must store the audio file on the receiver smartphone, in a folder that makes it visible under the phone’s ringtones. On my old A5000 smartphone (Android Version 2.2.1) I created a folder on the main storage (/sdcard/) named Media/audio/ringtones, and inside that folder I stored the new ringtone named 137.ogg; after this operation and after rebooting, the file appeared in the list of ringtones. When this new ringtone is in the list, you must assign it to the specific contact (or contacts) in your phonebook that is (are) authorized to play with relays; then you must set WA preferences to play the notification tone using the contact’s ringtone. To test this settings, send a WA message from transmitter to receiver and hear if the played notification tone is the one just assigned. After this, send a WA message from another phone (not authorized) to the receiver and verify that the notification tone is different (or absent).

Now it’s time to load and install the WhatRelay application from my page on Google Play Store. Once installed, at first run, the program asks for the working directory of WA. On my devices (both of them) this folder is on the main storage (/sdcard/) with this path: WhatsApp/Media/WhatsApp Images/ (take care of capital letters and last slash). Insert this path and accept. Please, note that all files IMG-xxxx.jpg already present on such folder will be renamed by the application in .IMG-xxxx.jpg (hidden), one every 5 + 2 seconds. If you want to preserve such files from renaming, move them to a new folder. In any case, every IMG-xxxx.jpg file present will be loaded and analyzed by the program, then renamed in .IMG-xxxx.jpg, so remove all such files before starting the App, or you will see them appear in the imagebox, be analyzed, then renamed at 5 + 2 seconds steps. The application sets the phone to stay always ON. Click the “quit” button to exit the application and restore the normal auto-turn-off time.

First run of WhatRelay App

First run of WhatRelay App

When the default path is set, the application starts, polling every 5 seconds the working directory to look if any IMG-xxxx.jpg file has been received. In the picture below, there is a screenshot of what happens when an IMG file is found. The image is copied in the small box at the right and after 2 seconds the program analyzes the picture to attribute a code. If the code is valid, a DTMF tone is played. In any case (valid image or not) the IMG-xxxx.jpg file will be renamed in .IMG-xxxx.jpg.

Program running: one IMG file has been received

Program running: one IMG file has been received

So, when WA receives a message, plays the notification tone that is the 137.ogg audio file, containing three DTMF tones that are the “key” to enable the circuit, then the WhatRelay App detects a new image, decodes it and plays the fourth DTMF tone (after less than 15 seconds) and the electronic circuits has received the key and the command, so can switch the relays. Job done.

Please, note that this is a release 0.1. This release will be revised many times. Look at this page or on Google Play Store to see if there is something new (and better). A special note regarding the volumes: remember that the circuit connects to the smartphone headphone plug, so put the volumes around 2/3 of the maximum and remove any notification that isn’t needed for the relays control. Do some tests without connecting the circuit, just to hear if all the tones are played with a good audio level. Use the local command buttons for other tests or for manual control of relays.

Spread your meteo sensor data over the internet

I published on the Italian Magazine for Electronics “CQ Elettronica” (issue N.485 September 2007) an article about my project based on Atmel ATtiny2313 microcontroller that converts the RF data stream (OOK modulation at 433 MHz) received from Oregon Scientific meteo sensor model THGR228NF (look at this link for more details).  This device was also revised by Hack-a-day in September 2007.

Recently, I created an Android App to display the received data on a tablet or a smartphone, using an USB-Serial interface to connect the receiver to the device. You can find the App on my page on Google Play Store and more informations at this link.

After the first version, I created a new one that uses a PIR sensor (Passive InfraRed) to swap the screen from a flip-clock to the meteo data screen when a person passes near the box. This is the prototype:

App in funzione su tablet 800x480 scala=1

Prototype running on 800 x 480 display 6.5″ Phablet

Well, after that I had the idea to publish my webcam on the Internet, superimposing over the picture (taken every 20 minutes) the meteo data received from the Oregon Scientific meteo sensor. This will enhance the picture with useful meteo data. Here is an example of what you can see clicking my webcam link :

webpic

click to reload actual view

As you can see, at the bottom of the image there are two information lines. Such lines are created by a PHP script that I stored on the server. The first line is the date and time of the picture, while the second is the date and time of the meteo informations (sent every 10 minutes), together with the temperature and humidity at the specific time.

The picture sent by the webcam hasn’t any information, being the camera a very simple device (look below how simple is..)

very home made webcam (click to enlarge)

very home made webcam (click to enlarge)

The bridge from the meteo receiver to the second line of picture is a new App written for an old 7″ tablet, running Android 2.2. This App does what the previous did, but every 10 minutes sends an HTTP GET request to a specific PHP script that I saved on the server. This GET request is formatted with a simple crypting and contains the temperature and humidity read from the sensor. The PHP script on the server receives the meteo data and creates a file with such infos. When the user clicks the link of my webcam, the PHP script loads the picture received from the webcam and the meteo data received from the tablet and creates on-the-fly the image you receive on your browser. Obviously, the tablet running the App connects to the Internet thru the home modem / router that acts as a WiFi hotspot.

I haven’t published this App on Google Play ’cause I decided to use, as communication port, the internal ttyS0 of the tablet. Such communication port was present in almost all the first models of tablets, but was used by the system for the “console” service. I modified the init.rc file of my rooted tablet (running Uberoid image) in order to disable the console service on that port, so I connected my RX-Met1 receiver directly to ttyS0 without any USB-Serial interface. This approach is too “specialistic” and therefore isn’t idoneous to the Play Store distribution. I just added a small video to show how I arranged the old tablet in a box with the receiver and the PIR sensor… (Dailymotion video)


MeteoRx22 di robotop

This way of sending sensor data over the Internet can be easily achieved with new low-cost modules, like ESP8266 that gives you the power of WiFi at very low price, with extreme easy of use.

IP Query – utility di rete per Android

L'icona dell'applicazione

L’icona dell’applicazione

Sempre più spesso gli smartphone vengono usati per connessioni Internet, non solo per la navigazione del Web o per la messaggistica istantanea, ma anche per il controllo a distanza di apparecchi collegati in rete. Ho così deciso di scrivere una piccola App che svolge due compiti : verificare se è possibile connettersi ad una certa “porta” su uno specifico IP e se si riceve risposta ad un “ping” inviato verso un IP. Nello screenshot sottostante si vede che la porta 80 (http) dell’IP 192.168.1.1 (il modem / router di casa) è raggiungibile.

Screenshot dell'App a seguito del comando Test

Screenshot dell’App a seguito del comando Test

In alto, sullo schermo, si nota l’IP locale dello smartphone, che essendo collegato in WiFI ha avuto dal server DHCP l’IP 192.168.1.9 . La porta 80 è raggiungibile perché il modem / router ha un’interfaccia di programmazione attraverso un browser web, quindi via HTTP.

Il comando di Ping invia un pacchetto ICMP e verifica che l’IP impostato sia raggiungibile. Alcuni server bloccano il servizio di risposta al ping per ragioni di sicurezza, ma nella maggior parte dei casi è possibile vedere se un IP è attivo ed operante.

Sia il comando Test che il Ping inviano una singola richiesta. Se si riceve come risposta un “no”, è opportuno eseguire di nuovo la prova per tre o quattro volte, per essere sicuri.

L’applicazione è disponibile gratuitamente su Google Play Store.

Terne Pitagoriche

pitagoraIl signore nell’immagine, che giustamente pensa di essere “troppo” forte, è Pitagora. Avendo una mente incline alla matematica, arrivò a calcolare che il quadrato costruito sull’ipotenusa è pari alla somma dei quadrati costruiti sui cateti (nel caso di un triangolo rettangolo, ovviamente). So che i Babilonesi arrivarono alla stessa conclusione diverso tempo prima, usando un metodo quasi “grafico”, e noi ringraziamo tutte queste menti brillanti e applichiamo la regola lasciataci in dono per fare i nostri calcoli.

Normalmente conosciamo i due cateti e dobbiamo trovare l’ipotenusa, oppure conosciamo l’ipotenusa e un cateto e dobbiamo trovare l’altro, ma recentemento ho aggiunto alla mia calcolatrice Android (scaricabile da Google Play Store, vedi link)  un tasto che compie un’azione diversa: possiamo inserire un valore per l’ipotenusa e la calcolatrice ci restituirà tutti i possibili valori dei cateti. Questa funzione è particolarmente utile a chi prepara gli esercizi per gli studenti, infatti con un semplice click si possono creare le cosiddette “Terne Pitagoriche”.

Prima di scrivere l’applicazione per Android, ho provato l’algoritmo sul PC, usando il solito FreeBasic. Ecco la schermata relativa ai risultati avendo dato in ingresso un valore di ipotenusa pari a 17.00 :

terne_ss

cliccare l’immagine per ingrandire

La precisione dei numeri è compresa nella regione delle due cifre decimali ; questo vuol dire che sia l’ipotenusa, sia i cateti sono numeri “precisi”, cioè sono terne esatte con al massimo due cifre decimali. Naturalmente, anche se nella schermata si vede A= 2.60 e B= 16.80, vale anche la soluzione A= 16.80 e B= 2.60 ; le simmetrie non vengono stampate dal programma per non dare un’inutile ripetizione.

Chi volesse provare il programma sul proprio PC, potrà scaricare l’eseguibile zippato a questo link ; per decomprimerlo occorre fornire la password che è: eficara . Per verificare che il file scaricato sia l’originale e non sia stato manipolato da biechi individui, potete controllare l’hash MD5 che deve essere: B09D351E99FB13C4E45993F0D56A12C9 .

Nota: ho inserito questa funzione anche nella mia calcolatrice Android (gratuita).

SeaMonkey: my way to backup

In my previous post, I suggested to create a backup of your SeaMonkey’s options before to try a change. Ok… but how can I save my data ? I don’t know if there is a simpler way or if my way is a “well known” one, but this blog was born just to collect a series of small notes that can be forgotten (by me) if not stored anywhere. So, please remember: this note is just for my personal use… if you want to try it on your computer, you’re free to do it, but you assume the duty of everything can go wrong.

I love SeaMonkey… it’s a browser, a mail client, and also an IRC client, if you like to chat. It’s free, it’s fast, it’s “light” and (in my opinion) it’s very easy to backup. Look at this screenshot taken on Win7 OS (click on miniature to enlarge):

0125_pic02The backup process is very simple. Search for the folder of your user account (on my computer, the folder is under /Users/EF) ; when found, simply right click on folder -SeaMonkey- and select “send to compressed folder”. The result will be the file SeaMonkey.zip. This file is a complete backup of all your Browser / Email and (I suppose, ’cause I don’t use it) IRC accounts. I tried to transfer all my accounts (email, browser’s preferences, passwords, buffers) to another computer running the “good old” Win XP OS. The only difference is the name of the folder (obviously, you would have a running copy of SeaMonkey on that XP computer). Look at this picture. The file path bar shows “Administrator” in place of “EF” and “Application Data” in place of “AppData”… but it’s always me :)

0125_pic01You can simply copy your SeaMonkey.zip file, saved under Win7, onto this directory. After that, rename the existent SeaMonkey folder with something like: “SeaMonkey-xp” and then unzip the compressed file ; this will produce a new -SeaMonkey- folder that’s is exactly the copy of the one you have on Win7 PC. Now, opening the SeaMonkey application, will give you a full copy on XP of all your (browser and email) data copied from Win7. Obviously, you can do the same on Win7 ; the zipped file is a real back-up. I use this way to save my data… may be there is one better or similar, it doesn’t matter for me ; this is “just the way I did it”.

About Win7, may be you cannot find the directory where the SeaMonkey data is saved, due to the “hidden” flag of such directory. I suggest to make all the folders visible, using the setting shown here:

0125_pic00The picture is taken on my PC, that runs Italian as default language. Run Control Panel, then search for “show hidden files and folders” and click the check box. The AppData folder will be visible, after that.

SeaMonkey Browser – modify the UserAgent string

ATTENTION, please ! Playing with browser’s preferences may DAMAGE or ERASE your browser’s and email accounts and data ! So, it’s MANDATORY to create a backup of the user’s profile before starting the activity !

I need for a sort of “filter” to make “private” some PHP scripts on my website. I just want that such scripts will work only when accessed by my PC’s browser. My public IP changes very often (it’s dynamic) so can’t be used as a proof of a request coming from my PC. An easy way can be to add a personalized message to the usual UserAgent string of my browser. I use “SeaMonkey” ’cause is very fast and “light” and also integrates the email client ; looking at the configuration options I didn’t found how to modify the UserAgent string, but googling for an answer I found that there is a preference that can be set to override the default one. The problem is that I don’t want just to override the “normal” UserAgent, but I just want to “append” my own string. So I created a very small PHP script just to know what’s my actual UserAgent. I called this script “UAget.php” ; it’s very simple, look at the picture below (note that clicking on the pictures loads 1:1 scale view)

The PHP script UAget.php

The PHP script UAget.php

I saved that script to an executable folder of my website (that can handle PHP scripts, obviously). Now, starting SeaMonkey and giving the URL of my script I had this result :

UAmod-pic1That’s my actual UserAgent. Well, I copied the whole string to the clipboard (ctrl-C) for future use.

UAmod-pic2At this point, I can try to add my personalized string to the UserAgent. For adding a new preference to the SeaMonkey’s configuration, you have to type “about:config” in the URL bar. You will receive an alert like this:

UAmod-pic3Don’t care about this, just click the button “I’ll be careful, etc” and go on…

UAmod-pic4Now you can see a list of option keys. Just click in empty space the right mouse key and on the descending menu choose: New, then: string and click for confirmation. You will be asked about the name of new preference:

UAmod-pic5The name will be: “general.useragent.override”, so write it down and click OK. Now a new box opens, requesting the string related to the new preference:

UAmod-pic6At this point, we paste (ctrl-V) the contents of the clipboard, that’s the original UserAgent string, and then append our personal string, in this example: ” Pippo/9.1.2015″, clicking OK to confirm. Look, our new “key” is part of the preferences list.

UAmod-pic7Ok, now we close the browser, then open it again and again we write the URL that points to our “UAget.php” script and this is the result:

UAmod-pic8Well done… our browser’s UserAgent, now, has an additional field: ” Pippo/9.1.2015″. This can be used in our PHP scripts to determine if the script itself will answer to requests or not, by means of parameter $_SERVER[‘HTTP_USER_AGENT’] used as filter. If the parameter contains our personalized string, then the script has been accessed by our browser (or by any other device that has ” Pippo/9.1.2015″ as part of the UserAgent).

Riciclare un vecchio tablet in flip-clock

Iniziai nel 2011 ad utilizzare dei tablet “cinesi” come economiche periferiche di I/O per i miei circuiti elettronici. Costruire “da zero” un dispositivo equivalente, cioè un display touch-screen 7″ a colori, con dispositivo audio, interfaccia USB Host, connessioni LAN e Wi-Fi, lettore di microSD, batteria ricaricabile al Litio di considerevole capacità e con un processore che “gira” a 800MHz o più, mi costerebbe almeno 150-200 Euro, anche se acquistassi i materiali per quantità non indifferenti (un centinaio di pezzi). Ricordo di aver comprato, negli anni passati, diversi modelli di tablet 7″ a meno di 70 Euro l’uno ed oggi costano anche molto meno ! Quindi, l’utilizzo di un tablet come periferica di I/O è sempre un “buon affare”. Ora, però, ho alcuni vecchi tablet da 7″ con touch-screen resistivo che non hanno più “mercato”, cioè sono superati come prestazioni per poterli utilizzare in nuove applicazioni e difficilmente “rivendibili” anche a metà del costo perché nei vari shop on-line si trovano modelli nuovi a prezzi “stracciati”. Allora… cosa farne ? Ecco la mia soluzione: un Flip-Clock, cioè un orologio “da parete” con le cifre che “flippano”, cioè cambiano come nei modelli meccanici dei vecchi tempi. Per chiarire il concetto, ecco lo “screenshot” dell’applicazione che gira su un tablet.

L'applicazione in funzione su tablet con schermo 800x480 scala:1

L’applicazione in funzione su tablet con schermo 800×480 scala:1

L’applicazione è stata testata su un vecchio tablet Android 2.2 con dimensioni di schermo 800×480 scala:1 e anche su un recente Phablet 6.5″ (Phone Tablet, quello usato per catturare lo screenshot visibile in figura) con Android 4.2 e comunque con display 800×480 scala:1. L’applicazione rimane sempre “accesa”, bloccando il normale autospegnimento del dispositivo. Se si desidera spegnere il telefono / tablet, si deve uscire dall’applicazione e quindi effettuare il normale spegnimento.
Nota 24 Mar 2015: Ho modificato l’App in modo che si adatti a diversi tipi di schermo. Ho anche aggiunto il cambio di modalità di visualizzazione da ore:min a min:sec e viceversa quando si tocca lo schermo. In modalità ore:min si ha anche il lampeggio ogni secondo di un “led”..

Tutto qui. L’applicazione è disponibile gratuitamente sulla mia pagina di Google Play .

Firmware e App per Meteo RX con Passive Infrared Sensor

Ho aggiunto al ricevitore per il sensore Oregon Scientific modello THGR228NF, che lavora in RF a 433 MHz (vedi link_1 e link_2), una parte di firmware per interfacciare un rivelatore PIR (Passive InfraRed) di tipo HC-SR501 o simile.

Sensore di movimento Passive Infrared

Sensore di movimento Passive Infrared

Lo scopo di questa aggiunta è di passare al tablet (o smartphone) collegato, l’informazione relativa alla presenza di una persona. Il circuito, tramite la connessione seriale, informa l’applicazione che c’è un movimento e così lo schermo passa da bassa ad alta luminosità (e viceversa). Sulle specifiche del componente si legge che l’uscita può avere livello 0V (non attivo) oppure 3.3V (attivo) ; il livello di 3.3V sarebbe un po’ basso come “logic high” per essere collegato direttamente al pin di input di un microcontrollore alimentato a 5V, ma usando la pull-up interna del micro e considerando lo schema interno del sensore (la linea di out ha una piccola resistenza in serie), si ottiene un livello accettabile.

Il ricevitore collegato al sensore PIR e di fianco il sensore Thermo-Hygro THGR228NF

Il ricevitore collegato al sensore PIR e di fianco il sensore Thermo-Hygro THGR228NF

Il nuovo firmware per il micro ATtiny2313 della Atmel è disponibile per il download ; il file zippato rxmet-ir.zip contiene il file .hex che si dovrà trasferire nel microcontrollore. La password per decomprimere questo file è eficara. La configurazione dei “fusibili” per il micro ATtiny2313 è la seguente:

High fuses: 11001001 (0xC9) Low fuses: 11011101 (0xDD)

Lo schema elettrico è stato modificato come in figura sotto ; non ho rifatto il circuito stampato, perché tutte le aggiunte sono state apportate semplicemente saldando dei fili alle nuove periferiche collegate (l’interfaccia USB-TTL e il sensore PIR).

Lo schema del circuito modificato

Lo schema del circuito modificato

Una volta programmato il micro, si potrà fare un test usando il terminale seriale di Windows (Hyperterm) o un qualsiasi altro terminale settato per 19200,N,8,1 come nella figura sottostante:

Il terminale seriale mostra messaggi ricevuti dal meteoRX

Il terminale seriale mostra messaggi ricevuti dal meteo-RX

Notate i messaggi IRsens=1 e IRsens=0 : questi vengono trasmessi, rispettivamente, quando il sensore PIR si attiva per un movimento “umano” e quando si disattiva. L’applicazione aumenta al massimo la luminosità del display nel primo caso, mentre la diminuisce nel secondo. In funzione della versione di Android e del dispositivo su cui si fa girare l’applicazione, si potrà avere un comportamento diverso ; la riduzione a zero, infatti, non ha un comportamento univoco. Sugli apparecchi che ho potuto provare, il display rimane comunque acceso con bassa luminosità, ma dalla “letteratura tecnica” sull’argomento, si deduce che in qualche caso lo schermo possa spegnersi del tutto. Modifica 23 Dic 2014: ho testato il funzionamento del comando di luminosità su un vecchio tablet Android 2.2 ed effettivamente, con la luminosità a zero, lo schermo si spegne del tutto e in più l’applicazione viene chiusa, cosa che assolutamente non è auspicabile. Per tagliare la testa al toro, ho modificato il programma in modo che la luminosità non vada più a zero, ma ad un valore appena superiore. L’effetto di “dimming”, visivamente, è identico, ma il tablet rimane acceso e l’applicazione attiva. In ogni caso, questa particolare applicazione, che fa uso di una interfaccia USB-TTL, non può essere installata su un dispositivo Android V2.2 , perché la gestione delle periferiche USB è completamente diversa ; nelle vecchie versioni di Android, infatti, se il chip montato sulla periferica USB è riconosciuto dal sistema, come nel caso del PL2303 Prolific o del CP2102 Silabs, nell’elenco delle periferiche (sulla directory /dev) appare la ttyUSB5, che può quindi essere utilizzata come porta seriale. Sul mio vecchio tablet (aperto, smontato e pesantemente modificato) ho utilizzato, per la comunicazione con il MeteoRX, addirittura la porta ttyS0 (la seriale standard), modificando l’avvio di Linux per disattivare il servizio “Console” normalmente attivo proprio su tale porta. Non pubblico su Google Play anche questa versione dell’applicazione, perché richiede la modifica del firmware del tablet per poter funzionare.

Nella foto sottostante vedete l’applicazione che gira su un tablet da 6.5″ con risoluzione 800×480, scala=1 :

App in funzione su tablet 800x480 scala=1

App in funzione su tablet 800 x 480 scala=1

Nella prossima foto, invece, c’è l’applicazione in funzione su uno smartphone con schermo da 4.3″ con risoluzione 1280×720 scala=2 :

App in funzione su smartphone 1280x720 scala=2

App in funzione su smartphone 1280 x 720 scala=2

L’applicazione è disponibile gratuitamente per il download sulla mia pagina di Google Play, mentre il circuito deve essere autocostruito perché non è disponibile in commercio. Buon divertimento… e auguri di buon Natale e felice anno nuovo :)