Sunday, December 13, 2020

Arduino Elecrow EL Shield

A long time ago i ordered on Aliexpress an Arduino EL-shield as it seemed interesting to play with it. Due to other priorities i never found time to play with it. When looking in my box with Arduino shields i decided to do a quick test. 

EL wire is flexible plastic wire that glows brightly when high-voltage AC is applied to it.

Numerous cool colors are available. They requires very little current, but it can be difficult to work with because of the high-voltage requirements. The Elecrow EL Shield enables you to implement up to 8 channels of EL wires or tapes in an Arduino  project to control the EL modules. 
The controlling method is as simple as controlling an LED. Driven by PWM, it can create a colorful and florid effect by controlling each EL wire according to your own programs.
With the shield 4 pieces of 2 meter are included The shield has 8 channels. See table below.


PINEL Channel to ControlPWM?(My Wire)
D2EL Channel A-
D3EL Channel BPWM( Blue )
D4EL Channel C-
D5EL Channel DPWM( Orange )
D6EL Channel EPWM( Green )
D7EL Channel F-
D8EL Channel G-
D9EL Channel HPWM( Yellow )

On the Arduino Uno Pin D3 D5 D6 D9 are PWM pins.
Therefore i decided to use these pins for the EL wires. ( Also tested the other channels on the EL shield and they all worked. However on D2 D4 D7 D8 there is no PWM )
When the EL wires are not powered and give no light the color is a bit different. I added in the table above the colors of my wires. 

The EL modules needs a driver voltage more than 110V, AC. The included Elecrow customized inverter can convert the 5V-DC input to AC,110~220V. 
Connected the inverter to EL-Shield as below:
The input wire of the inverter is red/white, which need to be inserted into the DC_5V terminal of EL Shield, and the output wire(black) of the inverter need to be inserted into the AC>110V termina
Specs say that can drive a max of 15m EL wires. 4 x 2 m = 8 meter EL wire was included so lighting them all up at the same is no problem.
As this is all the EL-wire i have i could net test adding additional EL-wire.

In the instruction ( ) First the Arduino is connected to a computer and a script is uploaded. After that the Arduino is disconnected from the computer. The shield is plugged in and an external mains power supply is used. As there is a high voltage on the shield (also near to the Arduino USB connector) i think this is the best way to prevent damaging your computer.
For some applications it would be interesting to see how long this shield can run on a 9 volt battery.
The disadvantage is that you need to plug and unplug connections when playing with the EL-shield. It also makes testing and debugging Arduino programs for this shield a little more difficult. An option could be creating a test with leds connected to D2 to D9 or using an good opto-isolation in the USB to your computer.

When running programs like the provided test program the system emits some low volume beeps and a buzzing sound. It is not a loud noise however i think it is important to mention it. It is possible the sound depends on the amount of power used by the wires and that only 4 of the 8 wires are connected.

On the EL-shield is also a red power led.
void setup(){
 for(int i = 2; i<10; i++)
  pinMode(i, OUTPUT);
void setEL(int ch) // set a certain EL on
  for(int i = 2; i<10; i++) // all on
 digitalWrite(i, HIGH);
 for(int i = 2; i<10; i++) // all off
 digitalWrite(i, LOW);
  for(int i = 2; i<10; i++) // 
  digitalWrite(i, HIGH);
  digitalWrite(i, LOW);
int count = 0; 
void loop()
 setEL(count%4 + 1);
 if(count++ == 1000)
  count = 0;
( The % in the Arduino program above is the modulo operator : count%4 is 'counter modulo 4 ' )

  • An interesting relative cheap Arduino shield.
  • The (2 meter long) EL-wires give an interesting light effect for a project. Perhaps for your project you will need another color or more wire of the same color. (I did not test other El-wires.)
  • Due to the high voltage generated by the 'Elecrow customized inverter' i did not want to take risks trying the EL-lights with the USB connected to my computer. A USB opto-isolator or a test shield with leds to D2 to D9 would be useful.


Saturday, December 12, 2020

Using Forth on my ELF II

Using Forth on my ELF II computer (including a CREATE DOES> explanation ) is the second article in a series about me and using Forth that started with my blogpost “My first computer and Forth” 
With Forth running on my ELF II computer with its RCA 1802 processor now real high level coding was possible.
I used virtual disk blocks with code stored in memory (loaded and saved to my system using audio cassettes). For coding in assembler an 1802 assembler in Forth was available. Also Forth text editor was published in a Forth magazine. I controlled hardware with Forth (an AY-3-8910 audio chip that I had added to my system). Forth became one the most important work horse on my system

In Forth you can new own words in vocabularies using : ; Do (complex) math in RPN using a (Forth) stack. Add extensions for floating point and strings. In my opinion one of the most powerful features of Forth is CREATE DOES> ( in the fig-Forth version when i started with Forth  <BUILD DOES> ).

Explanation of CREATE DOES>

Before i can explain CREATE DOES> (or <BUILD DOES> as it was called when i started with Forth) some fundamentals of Forth must be known. I do not give an in depth explanation however it is always possible to ask questions after reading this article.
Parameters (numbers) in Forth are passed using a stack.
(New) Forth words are stored in memory in a dictionary.
Things you type in using your keyboard are placed in a special memory area, the terminal input buffer. Space or spaces are used as separators between words and there is a character defining the end of line.
The Forth interpreter looks at the first word from the terminal input buffer and tries to find it in its dictionary. If found, there is also code to be executed in the dictionary. If not found Forth tries to convert it to a number and places the number on the stack. If not found Forth shows an error message.
After that (when there was no error) it continues with the next word until the end of line character in the terminal input buffer. The end of line character is just a special Forth word that prints an oke prompt and lets you enter a new line of text in the terminal input buffer.
Defining a new Forth word is placing a new word in the Forth dictionary together with the code that needs to be executed.
Example 1 : ; ( or colon semi-colon ) construction.
: My1stWord DUP 2 + . ;
The : puts My1stWord in the dictionary. DUP 2 + is the Forth code that belongs to My1stWord
; ( semi-colon) indicates that this is the end of the definition made by : ( colon )
Example 2 VARIABLE ( I do not encourage the use variables as often it is better to store things on the stack than in a variables)
15 VARIABLE My1stVar
15 is put on the stack. A variable with the name My1stVar is created containing the initial value 15 . ( I assume you have a Forth system where the initial value is on the stack. it is also possible you have a system where no initial value is needed/used.)
When the new Forth word My1stVar is executed it gives a memory pointer to the address where the value of the variable is stored. To get the value ( 15 ) we can use the Forth word @ This word uses the address (that is on the top of the stack) and fetches the value.
The magic of creating new words is CREATE DOES>
CREATE creates a new word in the dictionary and the DOES> part tells what to do.
Let make the Forth word JVAR to create a variable This is relative simple:
: defines the word JVAR
CREATE is a word that creates the dictionary entry. The dictionary entry contains a pointer to the DOES> part. So when the word is found in the dictionary it knows what to do.
, ( comma ) is just a simple word that gets a number from the stack and puts it in the dictionary.
And then there is the DOES> part, in this case seems to do nothing.
When we now enter 12 JVAR My2ndVar The variable with the name My2ndVar is created and available in the Forth Dictionary.
When the new Forth word My2ndVar is executed it gives a memory pointer to the address where the value of the variable My2ndVar is stored. To get the value ( 12 ) we can use the Forth word @
To change this to the behaviour of a “constant” where, when executed not a pointer but the value is on the stack, we could do something like
: My1stCONST My2ndVar @ ;
However this would be an uncommon way to create a constant as this is actually fetching a variable. Creating multiple constants would require for each constant also a variable.
Let us make a word JCONST to create a ‘real’ constant.
The @ is now in the DOES> part.
creates the word My2ndCONST
The DOES> part uses the address and fetches ( @ ) the value.
A very powerful way to make defining words at your own flavor as everything can be adapted in this CREATE DOES> concept.
For example create double size variables initialized with the value 0
: JDVAR CREATE 0 , 0 , DOES> ;
or do you want something else like a constant with a value that increments each time with one when a new constant word is created?

Forth has advantages and disadvantages. Floating point math, use of text strings. It was always a bit different from other computer languages. Most times with what I would call ‘more contact to what is really happening in the system’. I liked using less variables and using the data stack.

In my brain came the idea that the most beautiful programs are the smallest ones. When I was repeatedly typing (almost) the same code (copy and paste was that time not as easy as nowadays) programs could be done differently (and better). When you expect to find here a lot of real Forth code that you can enter in any Forth system I must disappoint you. However I present some ideas and parts of code that you can use in your Forth system if you know some of the internal working of your Forth system and add some code to adapt it to your Forth system.

A (lazy) simple program to control your hardware in Forth only needs
If you have created a smart defining word :LAMP with your system suddenly can understand what to do when you type
I used TOGGLE to switch it ON when the light was OFF or switch of OFF when it was ON.
TEST? to leave TRUE or FALSE on the stack depending on the current state.
OFF ON TOGGLE and TEST? can be implemented as constants that each push a different value on the stack.
The 1 2 4 or 8 are stored in these words so later on FORTH knows which hardware bit controls which lamp. The DOES> part is executed when the new defined words are executed.
It gives a pointer to the defined word so the correct hardware bit (and/or other parameters) that was stored during the <BUILD can be fetched.
OFF ON TOGGLE and TEST? pushed a value on the stack so the DOES> part can use it to determine what to do.
So on the stack are the bit/hardware parameters and what you like to do ( OFF ON TOGGLE or TEST? )
SWAP these, so what you want to do is on top of the stack. Using a CASE statement you can continue with the code to turn the bit/(hardware) high, low, toggle it or test the current state (and leave that as a flag on the stack).
To turn all the lights of you need something like
This as each device needs its own control parameter when coded the way described above.
Some people don't like that.
This can be solved in different ways:
Method 2 could be OFF ON TOGGLE and TEST? are not constants that were pushed on the stack. Implement OFF ON TOGGLE and TEST? as words that change a variable
Method 3 could be don’t eat the value of OFF OF TOGGLE or TEST? from the stack.
Change the code so it is after (successful) execution still on the stack. (Otherwise leave a special number indicating there was an error)
Another option could be that you don’t like the spaces between the command and word at all.
You do not want to create one word LAMP_LIVING
It should create multiple words (without spaces):
This is also possible because :LAMP can define multiple words e.g.
This as you can make :LAMP consisting of multiple defining words like
:LAMP_OFF has a CREATE DOES> to turn a bit off
:LAMP_ON has a CREATE DOES> to turn a bit on
:LAMP_TOGGLE has a CREATE DOES> to toggle a bit
:LAMP_TEST? has a CREATE DOES> to test a bit
Each of the defining words needs to know the hardware bit (in this case 2)
It is strange and can give errors if you need to do it as described before repeating 2 2 2 2.
Again this can be solved multiple ways:
One method is by duplicating the hardware bit (Except the last time)
Another method is to make the code of the defining words :LAMP_OFF :LAMP_ON :LAMP_TOGGLE :LAMP_TEST? keeping the hardware bit on the stack
The last word does not need to maintain the bit on the stack. However for consistency it let all words keep the hardware bit and DROP it at the end.
This way if you later-on add a new thing like :LAMP_BLINK you do not need to check which words change the stack.
This all to reduce the code from
What about improving the code so
would create in the Forth dictionary
This is not very difficult. You need to know in detail how (your) Forth creates new words.
CREATE (or <BUILD) gets the new word that needs to come in the dictionary from the terminal input buffer (TIB). Adapt this so you start each time again at the same word LAMP_LIVING and add the _OFF _ON _TOGGLE _TEST?
You need to DIG in your system to check how this is implemented. (Perhaps you have the word DIG to check Forth words).
So modify Forths so not the next word from the terminal input buffer is fetched (and eaten) but a word is defined including _OFF _ON _TOGGLE or _TEST?

Unfortunate i learned that in eForth there is no CREATE DOES>.  However i expect some of the ideas presented still can be used. For example modifying the defining words so not only the word comes in the dictionary, also with suffixes appended as _OFF _ON _TOGGLE _TEST?

Thursday, December 10, 2020

Testing two interesting 220V led light bulbs

 Recently i received two interesting main volt light bulbs from Aliexpress . These two light bulbs are both equipped with sensors. One has a PIR motion sensor. The other mentions a radar sensor. They both give light when someone is near the bulb and it is dark.
From both lamps several versions are available (Warm of Cold white and different watts).

PIR Lamp

Induction Lampe LED E27 B22 LED Night Light Lamp With PIR Motion Sensor Light bulb Luminaria Auto On/Off Detection Energy-saving.

I ordered 12W Cold White. And indeed it looks very cold white

"Radar" Lamp
Radar Motion Sensor E27 Led Lamp Bulb E27 85-265V Auto Smart Infrared Body Sensor Light Bulb For Home Stair Porch Aisle Garage
I ordered a 10W Cold White version

To compare the light bulbs i used a lamp socket with a main ( 220V ) connector and did some tests.
The led lamp with the PIR sensor has a little (additional) ball on top (for the sensor).
The led lamp with the 'radar' is, by just looking at it difficult to distinguish from an ordinary led lamp.

When connecting to mains both lamps first go on. I did not check if this was due to the design or due to the fact that i was near the bulbs.

After the last detection both lamps turn off after a delay of about 25 seconds.
After that they both only light up when sensing something if it is dark.
However the lamp with the PIR sensor is more sensible to light and for this lamp it needs to be a little more dark than for the radar lamp to turn on again when approaching the light bulb.

I did some simple tests to see if the lamps turn on when inside a bag, a box, or behind my computer screen. The lamp with the radar sensor was a little more sensible than the PIR sensor lamp. However the radar was less sensible than expected. So i have some doubts if it is really equipped with a radar sensor or just has another type of IR sensor. 
Also during these experiments when placing the PIR sensor in a bag it randomly turned on an of when nobody was near.

For a more extended test two lamps of a similar wattage should be tested including a power consumption measurement. Also a tear-down of the lamps would be interesting to check the sensors used. Especially for this 'radar motion detector lamp'.  At the moment i will not do such an extended test. I have seen some video's and there are several lamps with radar included. I don't know if there is a lot of variation between the sensibility of these lamps. 

To really know if these motion detection lamps will suit your needs and which lamp will be the best for which situation you will need to test them in the real location where you want to use them.

Wednesday, December 9, 2020

Arduino Uno enclosure

Today received some new mail items for Aliexpress. In the past i received items form each seller separately. However the last months i notice packages from several sellers get combined. I receive now packages containing several separate little packages.

Arduino Uno in enclosure (Front)

One item in my mailbag of today was a plastic Arduino enclosure. They are relative cheap and i have seen several pictures and video recordings where using this enclosure.
I ordered some to check if they fit my needs. Until now i used several times plastics plastic screws with my PCBs to put them better on my table.

Arduino Uno in enclosure (back)

 I like the plastic enclosure. I did find some little disadvantages:

  • Some Arduino shields have relative short legs and do not fit as nice as without the enclosure.
  • When putting a shield for the first time you must bend the shield legs a little, which is done better without the enclosure.
 Also in this blog a photo of the manual for assembling this enclosure. The enclosure came with a spare M2 screw and nut.

Thursday, December 3, 2020

My first programmable Car

This week i took some picture of my car to share on my blog.  It is a "Fantastic Car with a Brain". You program the car and you decide the action,

This Hasbro Amaze-A-Matics programmable car comes with some plastic strips with ready to use programs. Also some cardboard strips are included that you can cut to create your own "programs". 

The card with the program is pulled under the car along two mechanical sensors on the left and right.
One side contains information for the wheels ( Left Straight Right ) and the other side info for the motor ( Forward, Neutral, Reverse ).

The programmable car was one of my toys as a child and i expect the first programming experience.
So below probably the first 'programs' ever that i created. Perhaps you can even find my first programming bug. (The white cardboard ones are my programs. The plastic black one is one of the programs the came with the car.
I remember cutting my own cardboard when i used up the pre-printed cardboard provided with this car. 
As the "program" contains no (conditional) branches or loops. In my current definition, i would not call  it a real program. This 'programmable' car (see picture below) perhaps moved me in the direction of computers and Ford Forth.