Friday, July 15, 2016

ESP8266 Basic Buzzer Tone

Today a small ESP8266 Basic program to use a Buzzer with the ESP8266 module.

The frequency of two tones can be adjusted with the two sliders
BuzTime is the time between switching to next tone
' BuzzerSiren.bas

cls
let PinBuzzer = 15
' Connect Buzzer to GND and PinBuzzer

let BuzTime = 500

let BuzV0 = 200
let BuzV1 = 300

let t = 0

html | <h1>Test Buzzer</h1> |

html | <br><br>Freq 0 |
button " 0 " , [Sliders0Off]
slider BuzV0 , 0 , 500
button "MAX" , [Slider0MAX]

html | <br><br>Freq 1 |
button " 0 " , [Sliders1Off]
slider BuzV1 , 0 , 500
button "MAX" , [Sliders1MAX]

html | <br><br> |
button " Off " , [Off]

html | <br><br><br> |
button " Exit ", [Exit]

TIMER BuzTime , [LoopPrg]

wait

[Off]
let BuzV0 = 0
let BuzV1 = 0
wait

[Slider0MAX]
let BuzV0 = 500
wait

[Slider0Off]
let BuzV0 = 0
wait


[Slider1MAX]
let BuzV1 = 500
wait

[Slider1Off]
let BuzV1 = 0
wait

[LoopPrg]

if t = 0 then
io(pwo,PinBuzzer,BuzV0)
endif

if t = 1 then
io(pwo,PinBuzzer,BuzV1)
endif

t = t + 1
if t > 1 then
t = 0
endif

wait

[Exit]
io(pwo,PinBuzzer,0)
cls

end


The picture in this post is of a project
is a sneak preview form a project that i want
to publish next week on this blog.
As you perhaps can see it includes a buzzer and
 a ESP8266 and this program will run on it.

Thursday, July 14, 2016

ESP8266 and PIR sensor (1) Not Working (?)


As i have some of these PIR motion detecting sensors and i wanted to know if my (5 - 20 volt) sensor does work with ESP8266 test module.
The spoiler of the story is already in the title.
With the signal to PinPir (I tried several pins), GND and  +Power to VCC ( 3.3 Volts) i tested the ESP8266 with the program below. This program also toggles another led ( PinChk ) every time the timer routine tests PinPIR.
First the PIR sensor seemed to react on movements.The PIR sensor has a jumper for Single or Repeat Trigger and adjustments for Sensitivity and Time delay. I did not want false alarm signals so did more tests. 
My conclusion is this PIR module does not work reliable on 3V3 if connected the standard way ! This is not a big surprise, the specs say you need 5 - 20 Volts!
ESP8266 and PIR sensor (Not working !!)This configuration starts to give false signals after some time especially if you use the (more power consuming) RGB leds and afer a time you can even remove the PIR sensor and get almost the same results as without the PIR sensor.

' PIR test
cls
' Pin Pir 2 GPIO2

let PinPir = 2

' Pin Led    14 GPIO14
let PinLed = 14

' Pin Chk    4 GPIO5
let PinChk = 4

' Switch off the a RGB leds 
io(po,12, io(pi,1) ) ' 12  GPIO12 RGB led GREEN
io(po,13, io(pi,1) ) ' 13  GPIO13 RGB led BLUE
io(po,15, io(pi,1) ) ' 15  GPIO15 RGB led RED

x = 0
html | <h1>Test Pir sensor</h1> |
html | <br> |
html | <br>Pir sensor controls the Led<br> |
button " Exit ", [Exit] 
html | <br> |
timer 60 ,[PirChk]
html | <br> |
wait 

[PirChk]
' toggle PinChk checkled
x = x + 1
io(po,PinChk,x )
if x > 1 then x = 0

io(po,PinLed, io(pi,PinPir) )
wait

[Exit]
io(po,PinLed, io(pi,1) )
end

A negative result is also a result, i decided to publish it for you (and as a reminder for myself). Perhaps a part of the problem is the wiring of my ESP test module, but 3.3 Volt is also below the specs of this PIR module !
But this is not the end of the story. I did a search on the internet (i need a PIR sensor for my project) and found an interesting article about my module...  As i have planned some other things you have to be patient before i can publish my test results.


Wednesday, July 13, 2016

ESP8266 Shield

If you want to create a more permanent project 
With the cheap ESP8266 development board that i have ( see picture) and a breadboard you can easyly create temporary circuits. For a more permanent project, after having tested the circuit, you need a different solution.
The option present in this article is creating a shield on a PCB experiment print where the ESP8266 module can be plugged in.
Parts needed for this shield:

  • The ESP8266 Development module
  • 1 x Dupont pin header 2 male 
  • 1 x Dupont pin header 2 female 
  • 2 x Dupont pin header 8 female 
  • PCB experiment board

The first step in creating a shield for the ESP8266 development board is removing the LDR replacing it with two male pins.

(If you do not need the RGB led you can remove the led also.) The next step is soldering female connector on a PCB board. I did put the female connectors first on the ESP8266 development board male pins, plugged in the PCB experiment board and did the soldering. 
On my epsriment board i added 
2 female pins on G02 and F02
8 female pins from  H04 to A04
8 female pins form  H15 to A15
 The ESP8266 development board with the PCB shield will look like this.
The next step is adding some wires and components for your project.
I used (for the picture)
Red (VCC)
Black (GND)
Green (Signal)
Blue (Signal/RGB led)
The Signal lines where soldered at line 05 an 14 and a connection was made to the connectors on line 04 and 15. Wires for power where added at A02 and A03  (VCC)  and at A16 and A17 (GND).
If you add a DHT11 or other sensor to measure temperature (an humidity) it needs to be placed it as far as possible away from the ESP8266 if you don't want to measure the temperature from the ESP8266.
Also keep area free around the ESP8266 antenna.
In the pictures you also see two push buttons and a vibration/tilt sensor.
You can also put the LDR, removed from the ESP8266 development board on the PCB experiment print.
I recommend adding two male pins (at A01 and A18) as i later i discovered that, when using PCB experiment print and testing the circuit step by step by adding more functionality, it is nice to have additional power connections.
Do not forget to add connections on the copper side of the PCB where needed
As the component side of the PCB experiment board is faced to the component side of the ESP8266 development module somewires where bend trough the holes to the other side of the PCB.
Have fun creating you projects with this easy to build shield.

Tuesday, July 12, 2016

ESP8266 Basic Thingspeak

In the ESP8266 Basic command list i found
some commands to use Thingspeak. I already had the DHT11 Temperature and Humidity sensor connected (and there is a LDR on the test board). Some time ago i created a freeThingspeak account and tried to use it with my home automation system. So it was only a little step to try the ESP8266 Basic Thingspeak API. This is in the "ESP8266Basic Language reference":

FUNCTIONS (THINGSPEAK API)

To get started with thing speak visit there web site at https://thingspeak.com/
You need to have an account and channel/api key all set up.
These functions will only work if the esp is connected to a network with the internet.
SENDTS:
Will post the fields contents to the thingspeak service. Must use the thingspeak key and field number.
SENDTS({KEY},{FIELD NUMBER},{FIELD CONTENTS})

READTS:
Will return the last value published for the desired field. Must use the thingspeak key, channel id and field number.
Bla = readts({KEY},{CHANNEL ID},{FIELD NUMBER})


I want to record the DHT11 Temperature, Humidity and Analog input ( LDR )
First i tested one Channel and only one field to figure out the type of data (numeric or string) that was needed. When this was oke i  created 2 more fields on this channel
Field 1:  temp
Field 2: hum
Field 3: ana
and tried to write the data to this channel. In the program below key1$=key2$=key3$ = the secret key of channelA (and tested also some modifications of this program).
In Thingspreak i missed some data!
I tried  writing data in a different order to the fields i also missed data.
The best order to write data seemed  3 , 2 , 1 not 1 , 2 , 3
However the last field always missed data.
I played with delays and also with delays between writing to the Fields.
I created more channels did write date to different channels
( key1$= secret key of channelA,  key2$= secret key of channelB,  key3$= secret key of channelC)
Then all data did arrive!
I expect there is some little bug in the ESP8266Basic code or some strange thing.


PinDHT11 = 4
tkey1$ = "MySecretKey000000001"
tkey2$ = "MySecretKey000000002"
tkey2$ = "MySecretKey000000003"

DHT.SETUP( 11 , PinDHT11  )
html "<h1>Logging data and storing to Thingspeak</h1>"

TIMER 6000 , [GETDAT]
html "<h2>Start Store and log</h2>"
wait

[GETDAT]
t = DHT.TEMP()
h = DHT.HUM()
a = io(ai)
p$ = time() & ", Temp = " & t & ", Hum = " & h & ", Analog(ldr) = " & a
html p$

MyDatT = str( t )
MyDatH = str( h )
MyDatA = str( a )

SENDTS( tkey3$ , "3" , MyDatA )
html " ( Send 3 MyDatA: " & MyDatA & ") "

SENDTS( tkey2$ , "2" , MyDatH )
html " ( Send 2 MyDatH: " & MyDatH & ") "

SENDTS( tkey1$ , "1" , MyDatT )
html " ( Send 1 MyDatT: " & MyDatT & ") "

html "<br>"

wait

[EXIT]
end

Monday, July 11, 2016

ESP8266 Basic DHT11 Temperature and humidity


I tested a DHT11 Temperature and Humidity sensor
with my ESP8266 board flashed with ESP8266Basic.

For this test i did NOT use the KY-015 Temperature and humidity sensor module (From the Arduino 37in1SensorKit ) with a DHT11. However that module should also work fine.
There are also some ESP8266 development modules that contain a DHT11 module.
I wanted to use a  "bare" DHT11 on my testmodule to later use this in a hardware project.
ESP8266Basic has some commands for the  DHT11 Temperature and Humidity sensor
On this module i found the labels for the pins GPIO3 and GPIO5 are swapped.  (  also when using the  DHT11 ).
With the program below the Temperature and humidity are printed one time

PinDHT11 = 4
'  GPIO5 = 4    GPIO4 = 5 with my test board !

DHT.SETUP( 11 , PinDHT11 )
cls

print "<br>Pin : " & PinDHT11 & "<br>Time : " & time() & "<br>Temperature : " & DHT.TEMP() & "<br>Humidity :" & DHT.HUM()

end


Friday, July 8, 2016

ESP8266 Basic IR sensor

ESP8266 Basis can also read Infra Red sensor
The manual of version 3 ESP8266Basic contains a little error IR receiver part.

ir.recv.setup(pin)
set the pin used for the IR reception (IR receiver connected to the pin)
example:
ir.recv.init(5) ‘set the pin 5
Needs to be
ir.recv.setup(pin)
set the pin used for the IR reception (IR receiver connected to the pin)
example:
ir.recv.setup( 5 ) ‘set the pin 5

I used the demo program below to test a  "TL1838 VS1838B 1838 38Khz Universal IR Infrared Receiver"  ( Aliexpress : 100 pcs less than 7 euro / The 37in1 Arduino KY-022 sensor should also work fine.) on pin GPIO14:

'  IR receive demo  ESP Basic 3.0.Alpha 8 
' http://blog.jeronimus.net

ir.recv.setup( 14 )
wprint "<h1> Testing IR input</h1>"
irbranch [DoIR]
wait

[DoIR]
wprint "<BR>IR received : " & ir.recv.full( )
returngui

return

end

Sometimes i did get an additional signal code "ffffffff:NEC:0" but most times i receive usable codes.

ESP8266 Buzzer

Tested passive Buzzer with ESP8266 development board and ESP8266Basic.
Buzzer (+)  is connected to pin 15 (Where also RGB led is connected) . Other pin connected to GND.

If buzzer is connected to "not RGB pins" ( 0 ,2 4, 5, 14 ,16) the corresponding led lights up.
Program to test buzzer:
High and Low buttons are not PWM
only added for testing


cls
let d = 15
' Connect Buzzer to GND and pin 'd'

let v = 0

html | <h1>Test Buzzer</h1> |
html | <br> |

button "Low" , [SetPinLow]
button "High" , [SetPinHigh]

html | <br><br> |

button "SetSliders" , [SetSliders]
button " 0 " , [SlidersOff]
slider v , 0 , 500
button "MAX" , [SlidersMAX]


html | <br><br> |

button " Exit ", [Exit]

wait

[SetPinLow]
io(po,d,0)
wait
[SetPinHigh]
io(po,d,1)
wait


[SlidersMAX]
let v = 500
Goto [SetSliders]

[SlidersOff]
let v = 0
[SetSliders]
io(pwo,d,v)
wait

[Exit]
cls
end


Thursday, July 7, 2016

6in1 USB serial interface

6 in 1 Multifunction Serial Module CP2102 USB TTL 485 to 232 Convert Module 3.3V/5V compatible

Documentation:

1. Why this post?

I am experimenting with Arduino / Genuino and ESP8266. I wanted a spare USB TTL 5 and 3.3 V interface and found this interesting device/circuit on Aliexpress.  Due to it's interesting features and its price (in June 2016 it even dropped below 3.00 Euro!) i wanted to give it a try. I ordered it and received it after some time together with other interesting hardware.
Then came the main disadvantage of this module : documentation. How to use put the switches to use this device. Most internet pages contained info where to buy  this device or info in Chinese (with pictures!). I still need to test the device (Perhaps i will post some results in this blog, I will not test all modes!)  but i want to share some info that i have found  (for you and for myself! ) 

2 Short description

- A USB 2.0 to TTL UART 6PIN CP2102 Module Serial Converter. Connect MCU easily to your computer!
This item uses the USB to serial chip CP2102, it has the advantages of high-speed, stability, small size. It can help realize the equal energy level interconversion of the USB/TTL/RS232/RS485. It is the essential tool in communication debugging.
Also +5 an +3.3 Volt power

3 Long description 

.Small size: the PCB board size is just 3.1CM*1.8CM, it is even smaller than the U disk.
Compatible with the 3.3V and 5v
3.3V and 5V voltage: can use this module to provide power suppler for the Microcontroller , the max output current is 500ma.
Over current protection: on-board recovery fuse, it can protect the Microcontroller and the PC from the damage of the Short Circuit. The fuse will automatic shutdown and will be work normally after the recovery of the circuit.
Indicator LED: When begin data transmission, the indicator LED will light.
TTL electronic level interface.
232 electronic level interface.
485 level interface: Automatic transceiver control no need for the control line. Default receiving state, when sending data, the state will be changed into sending state.
USB, TTL, RS232,,RS485 four electronic levels free transfer: unique circuit design, uses the switch to realize the functions conversion, it is very fast and convenient.
Stable communication rate: The max rate is 1Mbps.
DTR,RTS control signals: Multifunciton, support MSP430 BSL download.- Stable and reliable chipset CP2102
- USB specification 2.0 compliant with full-speed 12Mbps.
- Standard USB type A male and TTL 6pin connector. 6pins for 3.3V, RST, TXD, RXD, GND & 5V.
- All handshaking and modem interface signals.
- Baud rates: 300 bps to 1.5 Mbps.
- Byte receive buffer; 640 byte transmit buffer.
- Hardware or X-On/X-Off handshaking supported.
- Event character support Line break transmission.
- USB suspend states supported via SUSPEND pins.
- Temperature Range: -40 to +85.
- Supports Windows 98SE, 2000, XP, Vista, Window7, Mac OS 9, Mac OS X & Linux 2.40.

4. Pins / connections

DTR
+5V
+3V3
TXD
RXD
GND

RTS
A
B
232T
232R
GND

USB connector

5. Switches

TTL - 232-485

DIL (2x)
485
USB

6. Functions

(Not tested /  found in documentaton!)

Model Dil code1(USB) Dil code2(485) Switch S1 Picture
USB to TTL
On
Off
Up(232-TTL)
USB to  232
On
Off
Up(232-TTL)
USB to 485
On
On
Up(232-TTL)
TTL to 232
Off
Off
Up(232-TTL)
TTL to 485
Off
On
Up(232-TTL)
232 to 485
Off
On
Down (232-485)

My comment: Picture above switch for 232-TTL / 232-485 seems different than text

USB
My comment: Strange, it seems switch for 232-TTL / 232-485 in pictures below is different

7. Interface usage:


Mode Pin Function
TTL Level Interface TXD TTL Transmit
TTL Level Interface RXD TTL Receive
TTL Level Interface GND TTL ground
232 Level Interface 232-TX 232 Transmit
232 Level Interface 232-RX 232 Receive
232 Level Interface GND 232 Ground
485 Level Interface A 485A+
485 Level Interface B 485B-
+5V Voltage Output +5V +5V Voltage Output
3.3 Voltage Output 3V3 3.3V Voltage Output
DTR Output DTR Special Function
RTS Output RTS Special Function

8.Product testing

I did not test this yet. This is only some text i found in "internet documentation" !
Using the USB TO TTL self-closed loop and the USB TO RS232 self-closed loop to test the product functions:

- USB TO TTL self-closed loop

Use the Dupont line to connect the TTL-TXD and TTL-RXD of this module, place the dial switch according to the function introduction, then insert this module into the computer, uses the serial debugging helper to send the data, check whether there has corresponding back data. If it can receiving the receiving data, it proves that this module can work normally.

- USB TO RS232 self-closed loop

Use the Dupont line to connect the 232-TXD and 232-RXD of this module, place the dial switch according to the function introduction, then insert this module into the computer, uses the serial debugging helper to send the data, check whether there has corresponding back data. If it can receiving the receiving data, it proves that this module can work normally.

The default state of the black two dial switch is "ON",  it is suitable for all conditions.

9.Mechanical drawing




10. Links

Explanation: 

Video + drivers