23 December 2014

Nativity scene light effects with Arduino - the code

And here is the code of my simple light effects. As shown in the previous post I used an Arduino-compatible board called "Pro Micro", compatible with "Leonardo". But any other variant will do.



/*
 Nativity scene lights

 This code controls two LEDs used to animate a Nativity scene.
 A normal LED connected at lampPin goes off during the simulated day.
 A high power LED (use an appropriate driver out of sunPin) simulates
 daylight, including sunrise and sunset fading.

 The circuit:
 * 5mm LED attached lampPin through a 1k resistor and 5V
 * high powered LED driven with an IRF510-like out of sunPin. It
   connects to Vcc through a limiting resistor (do your math and
   take heat dissipation into account).

 Created 20 Dec 2014
 By Paolo Cravero IK1ZYW

 Based on the official Arduino example "Fading":
 http://arduino.cc/en/Tutorial/Fading

 This code is in the public domain.

 */


int sunPin = 3;  
int lampPin = 9;

void setup()  { 
  pinMode(lampPin, OUTPUT);
  digitalWrite(lampPin, LOW);
} 

void loop()  { 
  // fade in from min to max in increments of 1 point:
  for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=1) { 
    // sets the value (range from 0 to 255):
    analogWrite(sunPin, fadeValue);         
    // wait for 50 milliseconds to see the dimming effect
    // adjust to your taste
    delay(50);                            
    // lampPin trigger is at 50
    if (fadeValue > 50) {    
      digitalWrite(lampPin, HIGH);
    }

  } 
  
  // duration of the day, 20 seconds
  delay(10000);
  delay(10000);
  
  // fade out from max to min in increments of 1 point:
  for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=1) { 
    // sets the value (range from 0 to 255):
    analogWrite(sunPin, fadeValue);         
    // wait for 50 milliseconds to see the dimming effect    
    // adjust to your taste
    delay(50);                    
    // lampPin trigger is at 50. Feel free to have hysteresis
    if (fadeValue < 50) {    
      digitalWrite(lampPin, LOW);
    }
  } 

  // duration of the night, 20 seconds
  delay(10000);
  delay(10000);
}

       
 

Nativity scene light effects with Arduino

It's Xmas time again. At home we deployed our usual nativity scene that had been joined by a simple 3V lamp for the barn, a couple of years ago. I wanted something more lively for my daughters, as well as something that originated from my hobby interests.

The idea: build a day/night simulation and switch on/off the barn lamp accordingly. Simple enough with an Arduino-like board and few lines of code.

How to simulate the Sun light, dimmable with PWM? The most intense light emitter I could find at home is a 1W warm white LED mounted on the "star" heatsink.

Step 1. If I let little Sun_LED draw 150 mA it doesn't warm up (to the touch), so I don't need a bulky extra heatsink. But I need an interface out of the Arduino board, because it cannot supply that much current. A good old IRF510 does the job (without heatsink).

Step 2. The 3V incandescent lamp drains 120 mA! I am lazy, in a hurry, and I don't want to add extra components to deal with it: a white LED does the job with 1/20th of electrons.

Last but not least, the whole thing is powered with a variable voltage wall-wart adapter. Since the Sun_LED is tied to the main Vcc supply through a limiting resistor, I can control Sun_LED maximum brightness with a flip of a switch.

Code and video will follow.

Improvements. My daughter asked for a moving figure: we will try to buy one during after Xmas clearout, possibly that works with DC. "I myself" though of simulating not only the fading of sunlight, but the color excursion too. I will buy a power RGB LED and play with it during 2015.

21 December 2014

ESP8266 really works on 802.11n?

Now that I got acquainted with ESP8266 WiFi module peculiarities, I have been asked if it works on newest 802.11n wireless networks. According to the datasheet, the ESP8266 chip supports 802.11b/g/n standards.

So I am setting up to test it against an "n only" access point. I will report my findings, since my home AP only does b and g.

09 December 2014

My best DX on 23 cm so far

My usual DX on 23 cm is 136 km during the monthly activity contest. Last Sunday there was the 50th anniversary of the Vecchiacchi V/U/SHF contest and I wanted to pay my tribute to the event.

All I could do was to spend the last contest hour on the air on 23 cm SSB. I was logged to the on4kst chat and got a request from a station 368 km away.

My 23 cm setup consists of a transverter with about 15 W out, 5 metres of SAT-TV coax and a 23 cm Yagi on the balcony, with "hand-rotor". The DX station was checking aircraft positions so that we could attempt an Aircraft Scatter QSO. At the first try my antenna was beaming too North. Then I adjusted it to what should have been the right direction and ... BINGO! The QSO was completed. We used three airplanes, that made a very long opening on our path.

Luckily I guessed how much off-frequency my transverter is!!

It is amazing how well AS works. Much similar to MS, but much more predictable!



30 November 2014

ESP8266 finally hears Arduino

As stated 18 days ago, I took a break from trying to make an Arduino board talk to an ESP8266 WiFi module. In the meantime I have both updated the 8266 firmware and received level converters.

Nothing changed: still no data flow from Arduino to ESP8266 over the hardware UART.

After three nights spent debugging software and hardware, trying to understand why both of them could happily speak to a computer, one at a time, but not to each other, I took the last chance: I fed directly the Arduino output at 5V/TTL. Make it or (literally) break it.

Well, it simply did it.

My ESP8266 specimens seem to be a "deaf" at 3.3 V, but they happily accept data at 5 V (datasheet says inputs are 5 V tolerant). ESP8266 power supply remains at 3.3 Volts.

More than ever, YMMV (Your Modules May Vary). I am not suggesting this procedure as standard practice. I report it worked for my specimens.


11 November 2014

Come aprire il tablet Mediacom SmartPad 820c

(This post is in Italian language since Mediacom products seem to be known only here...)

Mi è capitato un tablet Mediacom SmartPad 820c con questo difetto: si inserisce il caricabatterie, lui da solo inizia la procedura di accensione e dopo circa 10 secondi si spegne il display per ricominciare tutto da capo. La batteria non carica.

Avendo vissuto una esperienza simile su uno smartphone Galaxy S2 che ha comportato la sostutizione di un circuito integrato (in garanzia!), ho aperto il tablet.

Contrariamente a quanto si potrebbe pensare, non bisogna forzare sotto il coperchio posteriore in alluminio o la plastica nera, ma tra il display e la striscia blu in plastica. Qualche vecchia carta fedeltà fa al caso nostro:



Si comincia dall'angolo in cui si apre lo sportellino e si fa tutto il giro.

Un po' sospettavo la batteria, come visto sul mio tablet Mediacom. Ma in questo caso non è assolutamente gonfia e mostra una tensione di 3,2 V (è solo scarica). Il problema sembra proprio essere nel circuito di gestione della carica.

Si potrebbe scollegare la batteria, ricaricarla esternamente e ricollegarla, per recuperare i dati. Ma la decisione spetta al proprietario dell'oggetto.

Purtroppo il difetto si è presentato una settimana dopo la scadenza biennale della garanzia. E non pensate male!

10 November 2014

ESP8266, taking a break

After too many hours spent trying to make an Arduino board talk to the ESP8266 module, I decided to take a break and:
  • buy a 5V/3.3V level conversion module
  • upgrade ESP8266 firmware while waiting for the delivery
With the upgrade I should be able to reduce the serial speed to a more bearable 9600 baud and hopefully get more consistent behavior of AT commands.

I even built a converter board based on a circuit I found online. I replaced 2N7000 with BF245 from my FET drawer but all I got was wrong voltages or a form of short circuit. Nevermind, even if I am loosing a chance to learn something new, I do not have enough time for this kind of troubleshooting: I want to have that WiFi board working and uploading data!

07 November 2014

Filtering ESP8266 power supply

If your ESP8266 behaves erratically, the cause could be in the power supply.

Not every experimenter is properly equipped with a reliable 3.3 V source, neither was I. So I built a downconverter to power the ESP8266 WiFi board. The LF33CV LDO regulator should supply 500 mA continuous: plenty of headroom for the 200-250 mA peak requirement.

I configured my modules to join the home WiFi network a startup. A simple test for their presence is to run a network ping (the smartphone and Fing app comes very handy). When powered with the USB-to-serial converter, the round-trip-time smartphone<>ESP8266 was of 10 ms or so. That is: send a small packet of data to the remote device and measure how long it takes to come back the acknowledgment.

When I moved to the stand-alone circuit I started getting lost packets exceptions and much higher RTT.

I looked at the 3.3 V line and noticed anomalous spikes when the LDO was used. Instead the DC line was much smoother with another 3.3 V source.

A simple extra 220 uF across 3.3 V and GND fixed it. Actually I even improved RTT of a couple of milliseconds.

So, decouple that 3.3 V line!