Thursday, March 26, 2020

Time Lapse Camera

I decided I needed a time lapse camera video of the bus build. I have two of the ESP32-CAM modules from AI Thinker.

To flash the ESP32-CAM I hooked a FTDI USB-serial adapter as:

5v  -> 5V  (pin 1 sorta)
GND -> GND (pin 2 sorta)
Tx  -> UOR
Rx  -> UOT
IO0 - GND during flash, press reset once first


I first tried the example in the Arduino IDE for it. It seems OK so I looked for an example time lapse. I found https://www.bitsnblobs.com/time-lapse-camera-using-the-esp32-cam/ His code is called E8. All I changed was to un-comment the correct camera definitions.

It boots, takes a photo, writes it to the SD card and sleeps for about 15 seconds. Then repeats. Sounds just right.

I then found a micro SD card that I could reformat to FAT32.

To use it, it needs a mount. There is a mounting box at https://www.thingiverse.com/thing:3652452 that fit fairly good. The hole for the power wires is in the wrong corner for me so I just left the cover off.




I powered it with an 18650 battery direct to the 3.3v input pin. and mounted it to the forward bulkhead of the bus. I try to remember to take out the battery when I stop working for the day and put it back in the next time.

Converting the photos to a video was trivial in linux:


  pot$ ffmpeg -pattern_type glob -i "IMG*.jpg" ~/tmp/output4.mpeg
or
  pot$ mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -o timelapse.avi -mf type=jpeg:fps=12 mf://@frames.txt

Here is today's video:


Saturday, March 14, 2020

Air Purifier Managed by Tasmota

My daughter has been suffering with allergies this spring. I decided to install a new air Purifier in the house. It may also help with bacteria/virus control too. It is a UV light in combination with an ionizer. It installs in the heater air duct. It was easy to install, cut a 3 inch hole in the duct after the fan and screw it into the hole. Install the provided transformer inside the heater and plug it in.

The air purifier installed.

For the size of this house based on square footage, it needs the fan to run at least 20 minutes at a time and repeat every hour regardless of whether the heater is on or not. I didn't have a timer and Amazon wanted way TOO much! I did find a dual relay module in my extras box and an esp8266, NodeMCU V0.9. I've had them quite a while.

I had heard of Tasmota, an IoT home automation software for ESP based controllers. I had not played with it before. I could have just written a program and webpage, but I usually do not add the extra code for robustness. I hoped that tasmota did. I downloaded it and flashed the ESP. It only took a couple days to find the little nuances that stopped it from doing what I wanted (without reading all the docs!). I was caught by the desire to not use MQTT or any cloud services. Finally I found that "on system#boot" does not work without MQTT and mDNS set, so it needed a patch, I downloaded tasmota_8.1.0.10.bin from http://thehackbox.org/tasmota/


The dual relay module and the NodeMCU V0.9
In the end it only required a single multi-part rule to get the 20 minutes ON followed by 60 minutes of OFF. And it comes back for a re-boot/or power cycle controlling properly.



 rule1
   on system#boot do backlog ruletimer1 1800; power1 1 endon
   on rules#timer=1 do backlog ruletimer2 3600; power1 0 endon
   on rules#timer=2 do backlog ruletimer1 1800; power1 1 endon




A 3D-printed enclosure

I think the ESP needs to be outside the metal enclosure of the heater so it needs a protective case. I printed one with my Ender3 Pro.
The Tasmota WiFi interface on my phone
With the stock interface the fan can be turned ON or OFF.

The details, if you are interested:


I downloaded and installed tasmota from:

   https://github.com/arendst/Tasmota/releases/tag/v8.1.0
I then found that "on system#boot" does not work without mqtt and mDNS set, need patch
downloaded tasmota_8.1.0.10.bin from http://thehackbox.org/tasmota/

Then flashed it on a nodemcu V0.9 board with:

   esptool.py --port /dev/ttyUSB0  write_flash -fs 1MB -fm dout 0x0 tasmota.bin

The dual relay module on D2. (I don't need the second relay, but it is what was on hand.)



Nodemcu   Relay
5V --     VCC
GND  --   GND
D2   --   IN1
jumper to JD-VCC-VCC  not VCC-GND

connect WiFi on phone to 192.168.4.1 then set local WiFi configuration
reboot, net scan to find address. It may do mDNS.

config menu:  Generic(0)
 Save
D2 Relay1i(29)

Console:
rule on system#boot do backlog ruletimer1 1200; power1 1 endon on rules#timer=1 do backlog ruletimer2 3600; power1 0 endon on rules#timer=2 do backlog ruletimer1 1200; power1 1 endon
Save

Configure Other
  PurifierFan, purifierFan2
  Save

Console
  Rule1 1

Config- Save Config to-> /Config_tasmota_A450B3_4275_8.1.0.10.dmp

It has been working flawless for 3 days now. No sneezing or watery eyes since!

Thursday, April 4, 2019

Nodered, influxdb and Grafana

I had installed nodered to help monitor some of the systems on the boat and elsewhere some time ago. It has the ability to display some data, charts and plots with the extra "dashboard" module.
https://nodered.org/docs/getting-started/installation

I also installed mosquitto to collect data from the ESP devices and the OPis. I probably followed someone's notes, but I didn't seem to log it.
https://mosquitto.org/download/

It was OK for a while, but each time I restarted a display, it would start with no historical data. There was also no way to remove erroneous data. As I change things, plug in or forget to plug in things, I do get erroneous data points on occasion.

I tried sqlite/sqlite3 on op2e and croc for a while. It is like mysql, only a little simpler. I found an example flow for nodered and tried it for a while.
 https://www.youtube.com/watch?v=ccKspiI8FRw&feature=youtu.be
  https://flows.nodered.org/flow/36f2de38ed4bb62cf3a5e8fdc76d779e

Then I saw the youtube from Andreas https://www.youtube.com/watch?v=JdV4x925au0 and decided to try it.

It didn't take too long to get some data going into influxdb, but it did take some learning. The data had to be formatted just right to be inserted in a way that grafana could read it back.

For the simple case of a two values JSON string this is it. It did take a while fo make it this simple:


var tokens  = msg.topic.split("/");
msg.measurement   =tokens[1];       //get device  name from topic  level 3 /v1.6/devices/tokens[3]
var dest    = tokens[tokens.length-1];
inputjson   =JSON.parse(msg.payload);
msg.payload =inputjson;
return msg;
// End

For the more complex report for the disk space it took several days:


var tokens  = msg.topic.split("/");
sys = tokens[1];       

function extract(elem) {
    let extr = elem;// { fileSystem: "/home", percent: "96" }
   // node.warn(extr)
    var tag = {"host": sys, "filesystem": extr.fileSystem};
    msg.measurement = "Disk";
    msg.payload= [{"percent": extr.percent}, tag];
    node.send(msg);
    return extr;
    }
    
msg.payload.disk.forEach(extract);
// End

But it is working now.

The next hurdle was to get the data out into a graph with Grafana. A longer learning curve. And I'm not sure how to show it. Several windows for input all have to agree for the data to show up.

Overview


Just the battery monitor

Saturday, January 19, 2019

A Quick Look at RFID

Back in 2002, I was working a short contract in Seattle, just as the company was notified by Walmart that they must implement RFID on ALL of their products or no longer be eligible to sell through them. I dreamed of starting a consulting company specializing in implementing RFID, but then I realized I'd rather be retired and sailing in warm waters.

Just for kicks I ordered this RFID kit to evaluate, "MFRC-522 RC522 RFID RF IC Card Sensor Module". I would post a link, but I bought it in Chinese via Google Translate. It was only $2.63 so I couldn't pass it up.

I tested it on a Wemos D1 Mini, ESP8266, my current CPU of choice. The Arduino IDE has a library for the  MFRC-522 from  https://github.com/miguelbalboa/rfid. It includes several examples. It is 3.3v and has a SPI interface plus a RST signal.

I tried several of the examples and the reader actually works! The blue tag needed to be less than 1cm to read, but the white card worked out to about 2.5cm.

Writing also worked. Both types of tags are identified as 1kilobhyte. I only wrote my name so I didn't test the limits.



MFRC-522 RC522 RFID Card Sensor Module

Tuesday, January 1, 2019

More Battery Monitor

It was still too hard to tell whether the new batteries were coming up to full charge, so while I waited, I added to the monitor. I already have a current shunt for the old "Heart/Cruising Designs" monitor and now the Xantrex LinkLite, so all I had to do was hook the ADS1115 differential input channels to it.

I added the current monitor with amp hour calculation and a status web page to the Batt_volt_mon. I re-factored the code using the tab capability of the Arduino IDE rev 1.8.8.

I also copied from a friend the idea to make each tab's code optionally included at compile time with #ifdef's. This makes it easier to debug.


  #define DO_ADS
  #ifdef DO_ADS
     #include "ads.h"
  #endif //DO_ADS
     ...
  #ifdef DO_ADS
     setup_ads();
  #endif // DO_ADS
     ...
  #ifdef DO_ADS
     if ( (last_ads + ads_time) < millis() ){
       last_ads = millis();
       loop_ads();
     }
  #endif //DO_ADS
     ...

 
And I uploaded the new code to my github.

Top of the board with the modules out to see the wires
The bottom of the board

And then I documented the connections in Fritzing.
The Fritzing layout

Tuesday, April 3, 2018

Boat "House-Battery Bank" Monitor

The batteries on my boat seem to be failing. I decided to monitor the voltage to see how it is doing. I have 8 each 6 volt golf-cart deep cycle batteries wired series-parallel to give 12volts with 880 Amp-hours. But 2 have a shorted cell and are disconnected.

They are usually charged by 4 each 150 watt solar panels connected to 2 each 30 amp MPPT solar controllers. Also sometimes large frame alternators on the main engine or the diesel powered watermaker.

Anyway, the monitor is a Wemos D1 Mini with an ADS1115 4 channel A to D to measure the battery voltage. The 12volts (11.9 to 14.4) is outside the normal range of the ASD1115 so there is a resistor voltage divider implemented as a trimpot to set the voltage below the max allowed.

Also there is a cheap 3.3v buck converter on the board.

Once a minute it measures the battery (supply) voltage and sends to to node-red via mosquitto MQTT. It also checks for an OTA update each cycle.

The code is available on my GitHub: https://github.com/svkatielee/ESP8266_Arduino_projects





Thursday, March 29, 2018

Capacity Testing 18650 LiPo

I made a battery powered ESP8266 IoT device and wanted to check the real capacity of my 18650 battery. All 18650s are not created equal and may not be labeled correcdt either.

This is the setup:
Discharge through USB tester to load
First and last discharge the battery through a USB tester that counts milliamp hours.

Charging setup
Charge the battery with a USB LiPo charge module through the USB tester and note the mA hours.

Note the handy adapter board, electronic load and USB monitor are  from Aliexpress. But came as a bundle that I can't find today.The USB monitor is an ATorch brand.
i5i6S-Type-c-Micro-usb-MiNi-port-adapter-board-converter-battery-electrical-test-adapter-board

Wednesday, March 7, 2018

Refrigerator Monitor

This is the first version of frig_mon as a Wemos D1 Mini, a waterproof DS18B20 and a real time clock module. I wanted the data time stamped but the ESP8266 does not keep good time during deepsleep. I powered it with a 18650 battery direct with no voltage regulator, wired to the 3.3v pins. It seemed to function OK.

The fully charged battery at 4.2v is a little over the ESP spec, but it seemed to boot and run OK. The battery soon drops to around 3.7v where is lasts quite a while.


Wemos D1 Mini, RTC and DS18B20
Then I tested the lowest voltage the ESP would function. 2.6v appeared to be OK however soon the ESP burned up. The guess at the problem is that when the battery gets too low the ESP can't finish boot, so it retries, continuously depleting the battery without getting to the code that would stop it "if the battery is too low". It generates a lot of heat during this and overheats.

Testing the low voltage for the ESP
I noticed the Wemos board uses a lot of current even in deepsleep mode. It seems the USB converter chip does not sleep. And the voltage regulator consumes power even though the battery was plugged in to the output side.

So I switched to an ESP8266-007 on a breakout board with no regulator installed. Much better battery life.

A ESP-007 on a breakout board w/o voltage regulator

Also added OTA update capability, but then the -007 didn't have enough memory. I switched it for a -012E on a breakout board. I get more than a month run-time with 15 minute mqtt updates, and a check for OTA update.

The current board


The code is on GitHub at https://github.com/svkatielee/ESP8266_Arduino_projects

Tuesday, February 20, 2018

Compile OpenCPN 4.8.2 for Armbian

UPDATE:
As of Armbian 5.65 with Ubuntu Bionic this is not necessary. The Ubuntu PPA has arm version of the latest release of OpenCPN

A fresh clean install of OpenCPN 4.8.2 on Armbian 5.38 - Ubuntu 16.04 - Orange Pi PC Plus

My laptop is named pot, the Orange Pi PC Plus gets renamed cpn.

Download the latest desktop version of Armbian for the Orange Pi board you have. It still needs to be the Legacy kernel 3.4.113 because the accelerated GPU drivers are not yet in the mainline kernel.

Write the OS image to the sd-card:

pot# dd bs=4M of=/dev/sdc if=Armbian_5.38_Orangepipcplus_Ubuntu_xenial_default_3.4.113_desktop.img


Do the normal setup of a fresh image:

pot# scp /etc/hosts root@cpn:/etc
passwd, config networking, ssh-copy-id, scp setup, fix ~larryl/.ssh ownership, ./confi   
reboot   # to finish filesystem resize
updatedb  # for the locate command


I had to wait quite a while for the daily cron: apt to finish before I could do:

apt update; apt upgrade
apt-get install build-essential cmake gettext git-core gpsd gpsd-clients libgps-dev \
   wx-common libwxgtk3.0-dev libglu1-mesa-dev libgtk2.0-dev wx3.0-headers libbz2-dev \
   libtinyxml-dev libportaudio2 portaudio19-dev libcurl4-openssl-dev libexpat1-dev \
   libcairo2-dev wx3.0-i18
   ... 0 upgraded, 105 newly installed, 1 to remove and 0 not upgraded. (as of Feb 18, 2018)


The default build image does not have enough swap space for the compile so I plugged in a USB SSD that had alinux installed once and setup that swap partition:

mkswap -f /dev/sda2
swapon /dev/sda2
armbian-config   # set hostname to cpn and TZ to Asia/Taipei


Now to get and compile OpenCPN source as a normal user:

git clone https://github.com/OpenCPN/OpenCPN.git  
git ccheckout v4.8.2
cd OpenCPN; mkdir build; cd build
cmake -DCFLAGS="-O2 -march=native" -DBUNDLE_DOCS=OFF -DBUNDLE_TCDATA=OFF -DBUNDLE_GSHHS=CRUDE ../
make package
dpkg -i /home/larryl/OpenCPN/build/opencpn_4.8.2-1_armhf.deb 

******** errors *******
dpkg: dependency problems prevent configuration of opencpn:
 opencpn depends on libwxgtk3.0-0; however:
  Package libwxgtk3.0-0 is not installed.
 opencpn depends on libtinyxml2.6.2; however:
  Package libtinyxml2.6.2 is not installed.
******** errors *******


So this is the reason I hate Ubuntu, needlessly changing the package name instead of the revision fields so the dependencies no longer match the "new package name"!!! So adjust the depends in the package description file for the variable ending in "PACKAGE_DEPS" about line 98:

vi ../CMakeLists.txt
SET (PACKAGE_DEPS "libc6, libwxgtk3.0-0v5, wx3.0-i18n, libglu1-mesa (>= 7.0.0), \
  libgl1-mesa-glx (>= 7.0.0), zlib1g, bzip2, libtinyxml2.6.2v5, libportaudio2")


Add the v5 to the dependencies as above

cmake -DCFLAGS="-O2 -march=native" -DBUNDLE_DOCS=OFF -DBUNDLE_TCDATA=ON -DBUNDLE_GSHHS=LOW ../
make package
sudo dpkg -i /home/larryl/OpenCPN/build/opencpn_4.8.2-1_armhf.deb


If you have unmet dependencies, you can attempt to fix them with:

sudo apt install -f

Ready to configure OpenCPN with charts, tide data, connections and your favorite settings.

PS: The finished package should soon be up on github repositories.

Monday, December 25, 2017

Biquad WiFi Antenna

I have been having a hard time connecting to the free WiFi here in the marina. I have a Bullet-HP with an 8-DB vertical antenna mounted to the mizzen mast. It turns out it is blocked from the office by the mast. Being too lazy to climb up and change something, I did this.

Homemade biquad WiFi antenna


I have a spare Bullet, in case of failure, so I got it out. I didn't have an antenna for it. A directional antenna would be good since I am tied to the dock in the marina and don't move much. The Omni vertical is good for swinging around the anchor because it doesn't get blocked for very long.

I found plans for the biquad on-line. I used a square of single sided PCB (123 x 123 mm) and a spare "N bulkhead" connector that matched the Bullet. I didn't have any 12 gauge solid wire to strip, but did find a piece of 2mm brass rod. I bent it into the biquad shape, two 30.1mm squares. Then I soldered it 15.5 mm above the copper side of the PCB, one center corner to the center conductor of the N connector, the other to ground.

Now I can aim it at the office door and I get a reasonable connection.

I am having a lot of dropped packets when I ping the office router, but I don't think it is the antenna. Seems more like a problem in the office. I don't speak enough Chinese (only 3 words) to ask them to look into it.

Saturday, September 24, 2016

My Orange Pi SBCs

A few Orange Pis
I have been playing with Orange Pi single board computers (SBCs) some lately. This is a few of them in order of performance, counter clockwise from lower left:
  Orange Pi One, Orange Pi PC, Orange Pi PC Plus and Orange Pi PC 2E.

The OPi One is running OpenELEC with dedicated Kodi media center is used as Trinda's movie machine. The OPi PC is just for fun and testing. The OPi PC+ is the new built-in navigation system running OpenCPN chart-plotter. And the OPi 2E is the big compilation server for software development for the smaller ones.

All but the media center are running Armbian Jessie, a Debian based Linux for arm computers. It is a rapidly developing OS. I started just a few months ago with 5.05 and now just loaded 5.20.

Thursday, April 14, 2016

OpenCPN on Orange Pi an Allwinner H3 Arm SBC

I ordered a new Orange Pi PC and a Orange Pi One for $15.99 and $9.99 plus shipping. It has an Allwinner H3 CPU with a Mail-400 GPU. They are supposed to perform a little better than the Raspberry Pi 2. So I thought I'd give it a try. The OPi One is a little short on memory for compiling, so I started with the OPi PC.

The details: (as of Apr 15, 2016. Check you revisions.)
There are several choices for an operating system, I chose armbian.com 's Debian Jessie. This OS is also available for several other H3, A10 and A20 CPUs by Allwinner such as the Banana Pi, CubieBoard, etc. These instructions may be adapted for them. They recommend a real class 10 SD card, not a fake. I this card seems a little slow but it is what is on hand.

Orange Pi PC w/ Samsung 8GB SD class 10, but only 4.2MB/s write speed when copying the image with this:

myrealpc$ sudo dd bs=4M of=/dev/mmcblk0 if=Armbian_5.05_Orangepih3_Debian_jessie_3.4.110_d  esktop.raw

Next boot the OPi PC from the SD card and setup the system. At armbian 5.05 there are several things to setup that will likely be changed in the next release (any day now). Other distributions will have different configurations. In addition to creating users and setting passwords, you should at least do:

orangepipc$ sudo apt-get update
orangepipc$ sudo apt-get upgrade


This was a 79 MB download this time, last week only 48MB.
Next install the necessary commands and libraries for compiling:

orangepipc$ sudo apt-get install build-essential cmake gettext git-core gpsd  
gpsd-clients libgps-dev wx-common libwxgtk3.0-dev libglu1-mesa-dev  
libgtk2.0-dev wx3.0-headers libbz2-dev libtinyxml-dev libportaudio2  
portaudio19-dev libcurl4-openssl-dev libexpat1-dev libcairo2-dev


Get a copy of the current opencpn source code. Change to the directory where you want to store the code, my home dir.And create a build directory.

orangepipc$ cd 
orangepipc$ git clone git://github.com/OpenCPN/OpenCPN.git
orangepipc$ cd OpenCPN
orangepipc$ mkdir build
orangepipc$ cd build


Make these changes to the CMakeLists.txt  in order for the Mali-400 drivers to be included:

orangepipc$ nano ../CMakeLists.txt

#  find_path(OPENGLESv1_INCLUDE_DIR GLES/gl.h )
  SET(OPENGLESv1_INCLUDE_DIR "/usr/include/GLES" )

The default swap size for this distribution is 128MB, not nearly enough for opencpn to compile. Therefore I plugged in a USB stick with a linux on it which had a swap partition on partition 5. To temporarily add swap space I did:

orangepipc$ sudo mkswap -f /dev/sda5
orangepipc$ sudo swapon /dev/sda5


The Mali-400 graphics accelerator driver is not found in the directory opencpn is looking for it. So I made a symbolic link to the expected directory. The error was:

 ERROR: /usr/bin/ld: cannot find -lEGL 
 
orangepipc$ sudo ln -s /usr/lib/mali/libEGL.so /usr/lib/


The OS should be ready to compile at this point. Use cmake to create the Makefiles for the compile. There are a few options available as per the OpenCPN site:
Default install dir is /usr/local, you can change this by providing the appropriate option to cmake: $ cmake -DCMAKE_INSTALL_PREFIX=/usr ../ If you're not into debugging, change to this to generate a smaller and marginally faster binary: $ cmake -DCFLAGS="-O2 -march=native" ../
It took about 2 hours for the compile. The first time through, just to satisfy me it succeeded, I directly installed opencpn as below.

orangepipc$ cmake ../
orangepipc$ make clean; make -j1
     # go drink some coffee, we're talking about a $15 computer compiling
orangepipc$ make install


It WORKS!! mostly.
I decided to try the optomized compile next so I:

orangepipc$ make clean
orangepipc$ cmake -DCFLAGS="-O2 -march=native" ../ 
orangepipc$ make -j1

orangepipc$ make package


You can then install the package with:

orangepipc$ sudo dpkg -i opencpn_4.2.0-1_armhf.deb 


Installing this way did not include the default world map or tcdata and I haven't heard the ships bells yet.

The map and tcdata can be included by following the instructions here. Or simply copy them in from another copy of opencpn (my Ubuntu15.04 laptop with opencpn 4.2 installed for instance) while you are copying in some charts to view.


There were a number of steps to cleanup the armbian 5.05 for automount the USBsticks etc. that I intend to document on my blog. At the rate the Armbian team is progressing, the OS cleanup will not be necessary for long.

Saturday, March 12, 2016

ESP8266 Design Contest Entry NMEA Bridge for OpenCPN

 !! Update edited Fritzing schematic Apr 28,2016 !!

 
Everything ESP8266  had a Design Contest In March 2016. The following was my entry, viewable at http://www.esp8266.com/viewtopic.php?f=152&t=8738



An ESP8266-01 WiFi module to read NMEA marine serial data and UDP broadcast it to multiple openCPN instances as a Bridge.

On my boat and several others, we are running OpenCPN for navigation software. Most of us run it on a laptop. The common inputs are GPS, AIS and some have all their instruments connected as well; depth, wind, speed & distance log, etc.

There are two problems that I am trying to solve. First, too many cables to the laptop providing the instrument data. And second, a way to share the instrument data with multiple devices. The release of opencpn for android tablets and smart phones makes it feasible to have multiple displays around the boat. Like in the captain's bunk to check on the boat and crew performance without getting out of bed.

So this friend that wants all of the instrument data over the network has a multiplexer that takes his SeaTalk and various NMEA 0183 signals and outputs a higher baud NMEA sentence data stream. And I have a combination AIS/GPS that has NMEA 0183 at 38400 baud. My laptop is getting old and if you touch the USB cable from the RS-232-to-USB it disconnects and reconnects using a different port configuration.

And besides it would be nice to have no cables, especially to a phone or tablet.

Along comes the ESP8266 Serial WiFi module with a modest price around $2.50 USD and other board configurations for a few dollars more.

So the plan is to create new firmware for the module, connect the rs-232 based NMEA 0183 signals to it and broadcast the sentences over the WiFi as UDP packets on the local subnet. So this will require a WiFi Access-point (AP) on the boat. (ED. It may be possible for the ESP to be the router too.) Another recent development is the availability of cheap pocket routers such as the TP-LINK WR702N. I picked mine up in Singapore for less than $8.00 USD last year, but the market is full of competitors.
I want to be able to run openCPN on both a laptop and a tablet at the same time. I would like the laptop down below deck, safe from the rain and salt water spray. I would like to have a mostly waterproof tablet in the cockpit to monitor progress. And I would like to be able to quickly check the ship's status from the captain's berth when off watch, maybe on a smart phone.

I decided to implement a device to read the serial data from all the boat instruments and send that data to openCPN over a WiFI link so there are no physical wires attached. It will broadcast the data with UDP so that multiple devices can read the data at the same time.

The ESP8266 ESP-01 was chosen because it was on hand and it has adequate I/O for this project.


NMEA 0183 is usually rs232 or rs484 at 4800 baud. The rs-232 input signal voltage should work with -12 to +12 volts. This project was tested with a Garmin 72H which outputs -5 to +5 and 4800 baud and an OceanPC AIS which outputs -3.0 to +3.0 at 38400 baud. Therefore, after a little search, I found a single transistor level shifter for the Rx input to make it conform to the 3.3v TTL levels of the ESP module.



Figure 1a. Strip-board implementation


Figure 1b. Strip-board bottom

The +5v power (from a 12v automobile USB charger module) comes in through the switch, upper left then a 3.3v regulator and then to the ESP module's socket. It is a little sensitive, so pull-up resistors are recommended on the 3 data lines, GPIO2 and Rx) and the chip select and reset pins. Tx and Rx are needed for programming (flashing) the firmware, and as a development board I chose to bring those to the top right pins with a ground for a future test of a 16x2 serial display.




Figure2. Schematic

The LEDs and pins at the bottom show the state of the 2 GPIO lines. The software configuration technique uses a short between these to go into config mode. The push button puts the module in flash mode.

First Usage

Connect power lines and input signal rs-232 line with ground. Press and hold config button, press reset, continue to hold config until the LED stays lit. Connect to the AP "NMEA WiFi Bridge" with a system/phone/etc. Connect your browser to 10.1.1.1 with password in code "nmeawifi".` Configure the form for your network and click the "configure" button. Verify the results page. Press reset or cycle power for the module to connect to your network.

To verify it is working, there is a status page on the address on the NMEA WiFi Bridge. Type this address into your browser.

The design of the code has three parts: setup configuration, normal execution and a status webpage.

First, setup configuration, short GPIO0 to GPIO2 (press the config button) and turn on the power. After a few seconds (5-6) the LED comes on indicting the module is ready to configure. This starts an AP at 10.1.1.1 that you can connect to with a WiFi capable device (laptop or phone or tablet using DHCP), then access the webpage at that IP. You get page_1.jpg.




figure 3. Setup


Enter the ssid and password for your boat network, the UDP port to connect and the baud rate to listen for the NMEA data.

When you click configure, it displays a confirmation of your data. If it is correct, turn off the power, connect it to you NMEA data, remove the short between the GPIO pins (do not press the button) and turn on the power.



Figure 4. Confirmation

The second part of the code, normal execution, now runs. It listens for NMEA sentences and when it has a complete sentence, broadcasts it to the broadcast address of the subnet you provided in config. All devices on that subnet can read these UDP packets.

Now go to your opencpn configuration settings, then connections. Add a new connection, selecting: network, UDP and the port number from above (default is 10110).
You should be getting data.



Figure 5. Status

The third part consists of a status page. You can look in a web browser at the IP address of the NMEAWiFiBridge and get a status page that updates the number of sentences broadcast every 10 seconds. It may severely impact the ability of the ESP to keep up with a busy data stream to monitor it, so it is only there to help with trouble shooting the connections. It should only impact performance while your browser is displaying the page.


  Figure 6. Rev 3 installed

Since the initial build I have made custom boards (3 trys to get them right) and have 2 installed and running aboard the Katie Lee.

See my github repository for code and schematics: https://github.com/svkatielee/NMEA_WiFi_Bridge  https://github.com/svkatielee/NMEA_WiFi_Bridge

The configuring software is based upon the work of Forward Computing and Control. My hardware is open-source, my software is GPL3.

Parts
1 - ESP8266-ESP-01
1 - LD1117-33 regulator (any 3.3v > 500ma will do)
1 - 1uF tantalum
6 - 4.7K ohm pull-up resisters
1 - 330 ohm current limit for Tx buffer
1 - 10K ohm for rs232 level convert 1 - 2n2222 for level convert
1 - 1N5819 program Rx input
1 - LED
3 - momentary pushbuttons

Links
Code and schematic on Github

Tuesday, February 2, 2016

Programming the ICOM M710 with DIY CI-V

Success and failure...USB-TTL to ICOM M710 programming cable

I need to reprogram my I-COM M710 Marine SSB/HAM HF rig. I have been using it aboard my sailboat since it was new in 2006 with an older Pactor IIe.

I would like to play with WinMOR and soundcard modem and some of the digital modes.

I searched the Internet and found most people were making (8 years ago) clones of the ICOM interface OPC-478.

So I first made clone cable like the CI-V cable  with  dual 2N2222s, a diode, some resisters and a DB9 connector. It needed to be plugged into my current laptop with a USB-serial adapter/emulator.  It failed. I must have put a transistor in backwards or something. Then I found the ICOM software. The software for cloning and configuring the M710 seems to be EX1726.exe (for 710RT use ES2144.exe) for DOS. It does direct manipulation of the serial port register so a PC with an real DB9 serial port running DOS, not Windows, would be required. I do not have these.

I kept searching.

I next found web page that says the ICOM clone port is TTL open collector, just one wire. And also elsewhere found the clause, "NMEA 0183 sentences at 4800 baud".

And a note describing how to make a clone cable from a USB-TTL adapter, commonly used to program Arduinos, and a phone plug.


   connect tip of mono phone plug to Rx and Tx soldered together and ring to ground of a USB to TTL serial adapter. I used a PL2303 based 5 pin adapter.


Mine shows up in syslog as:

Feb 2 14:50:18 nav3 kernel: [27157.768171] usb 1-4.4: Manufacturer: Prolific Technology Inc.
Feb 2 14:50:18 nav3 kernel: [27157.768585] pl2303 1-4.4:1.0: pl2303 converter detected

The user  belizesailor at Cruiser Forum says the DosBox emulator for games emulates the serial port so well that the ICOM software will work.

OK! I quickly made the cable for the USB-TTL adapter in the photo. Then downloaded DosBox from www.dosbox.com, for debian to my ubuntu 15.10 system.

I actually used the synaptic package manager and checked the box to include dependent packages from the repository. It worked fine. All this after a failed attempt to download the source tar ball and compile it myself. And I had also tried to install the packages on WinXP, but I have no XP driver for the Prolific USB.

Then found EX1726.zip at http://ea4yx.jimdo.com/software-radioaficionados/control-equipos/software-icom/

After unzip'ing it, edit the config file ~/.dosbox/dosbox-0.74.conf
 to set the serial ports to emulate, these two lines:
 
serial1=directserial realport:ttyUSB0
serial2=directserial realport:ttyUSB1


So to program the M710 from Ubuntu-Gnome 15.10, select:
Menu> Games> DosBox

Then in DosBox:


Z:\> mount c ~/Data/Radio/EX1726

Z:\> C:

c:\>  ex1726 /expert       # see the README maybe called M710.DOC

ESC > Clone > Rs232 >port2    # ttyUSB1

ESC > C > T   # read from transceiver to PC

....





Thursday, January 14, 2016

A New Laptop

Another laptop bites the dust.

(Updated Jan 31)

A few months ago my oldest laptop died an unnatural death. It was an Acer Aspire One about 6 years old.

I finally got tired of the other one freezing and complaining, so I went to town(Cebu, PH) and found a replacement. I had had good luck with the cheap Aspire Ones, so I just picked the best one Acer had in the market here.

Acer V3 15inch i7 8Gb 1Tb 2.4Ghz  -  V3-547G-77P6

It came with Windows 10 64bit. The hardest part about that was the decision of which Linux distribution to dual-boot with it. The Internet here is terribly slow, so the choice was limited, one year old LinuxMint 17.1 64bit, Ubuntu 14.04 32bit or Ubuntu 15.10 64bit.

It seems Windows 10 insists on EUFI type BIOS for boot configuration and boot loader. After a couple weeks I had upgraded the "BIOS" to the latest rev on Acer's support site, learned to select the next boot device from in Windows 10 menus, almost worn out the install media, re-partitioned the disk several ways and had working 14.04 and 15.10 on separate partitions alongside Windows.

The Acer barely acknowledges the F2(BIOS) and F12(boot order) soft-keys during post. After finding the Windows command to go to boot menu things got a lot less frustrating. Click Power then hold shift and click reboot for the F2 BIOS menu during boot, or pick the file to boot on the next power up.

I tried installing with the BIOS set to ignore EUFI, but then Windows10 would not boot.

The final answer is to upgrade the BIOS(to v1.31) from the default(v1.25) so it can boot a linux. Then install with EUFI enabled to secure mode and grub in the EUFI partiton, then in the BIOS set the grub file to be trusted, and there also set the boot order of the EUFI systems. Setting the boot order in Linux (efibootmgr -o 4,1 ) or in Windows 10 does not work.

I spent the next couple weeks doing all that system admin I had nearly forgotten. I installed VMware and VirtualBox. Then WindowsXP, Andy's HAM Radio, LinuxMint17.1-64bit as virtual machines. I also attempted to visualize the old Acer Aspire Windows 7 and LinuxMint physical drives into VMware, but got sidetracked about the time I realized I needed to do it from VMware instance installed in a Windows host OS.


THEN THE ACER V3 DIED!!!!

I took it to the local Acer repair/warranty center in Cebu. Tomorrow I am to get it back and have the notes to correct the above procedures.

Monday, December 28, 2015

More NMEA Bridge modules

I finally got around to testing the last 2 WiFi Bridge boards. Neither worked at first. I wasn't sure of anything.

I chose one board and went through the entire regression. When I finally got the scope (Xprotolab) out and followed the NMEA signal in, I found a broken trace. The input to the first resistor. Arg! Then I discovered I put the transistor in backwards in both boards.

But now they are both installed and broadcasting. The first is connected to the builtin Garmin GPS and depth finder data, wire-or'd on the same terminal strip at 4800 baud. And the second is connected to the AIS at 38400 baud.

Then I etched two more boards, but haven't drilled or populated them yet.

Sunday, November 1, 2015

Two More NMEA WiFi Bridge Boards

If I could only learn to take good photos
I etched two more of the NMEA WiFi Bridge boards. After only a week of messing with the layout in Eagle, I finally decided I had a valid rev x.3. It seems I left a Vcc trace off the x.2 board.

Printing the inkjet transparency went well this time, marking solid and black in eagle print, although the color came out greenish. I exposed the pre-sensitized board 1 minute 15 seconds in the 1:30 afternoon equatorial sun then immediately developed them in caustic soda from last year for about 3 minutes. Then etched in new peroxide and muriatic acid for about the same 3 minutes. They looked really nice for a change.

I then exposed them to the sun again for 2 minutes and used the caustic to get the rest of the green photo-resist off the traces so I could solder.

I tried to coat all the copper with solder, but the very fine letters just pealed off the board. I had levf a +, -,  G and Rx in copper near those pins.

It took less than 3 hours to print, etch and populate the 2 boards. Of course that doesn't count the week fussing with the layout!

I decided to leave the voltage regulator off these because I have a number of $2 Chinese buck converters that have good regulation in the 3.3v range to pair them with.

Sunday, October 18, 2015

A new board for the NMEA WiFi Bridge

I made a second strip-board copy of the NMEA WiFi Bridge. It took too long, a whole day. So I spent several days designing and etching a custom board. It only took a few minutes to populate.

I have been experimenting with taking close-up with my phone. This is looking through my 10x monocle I use to examine the boards.


The finished and corrected board with a Chinese buck DC-DC voltage converter set for 3.3 volts. After all the debugging, I left the LD1117-33 out and jumpered over it.


Maybe it assembled faster because I had left off a trace. Seems that eagle doesn't always name VCC as VCC. I put a regulator chip in the schematic, then when designing the PCB, I switched it for a different one. I inadvertently must have named it net $NS3. Well you hardly notice the little blue wire-wrap wire anyway.


I have been designing SMD  boards for the ESP-01 and ESP-12E, but haven't made them yet. I seem to have tentative requests for 4 more of these. Seems nobody likes wires to the laptop while underway.

Saturday, October 3, 2015

12 Volt LEDs for a Boat

I needed some new lights in some places on the boat. Many of the LED light strips and and clusters these days use either 12 volts or an AC adapter for 12 volts. Some even say "for car".

However on closer inspection most of these have only a current limiting resistor in series with sets of 3 LEDs. Thus they are suitable for ONLY 12 volts and below. Boats and cars are nominally 12 volts. That means they are NOT 12.0 volts. My boat runs from 12.4 to 14.4 volts depending on the state of charge of the batteries, the sun on the solor panels and whether the engine/alternator is running.

The advertised long life of LEDs is dependent on ideal conditions. The 2 main areas of abuse LEDs suffer are over temperature and over voltage.

In the tropics, the only thing I can do about the heat is by choosing how and where they are installed. They should get natural cooling of have a cooling fan.

For over voltage, what I have discovered is the LM2940T-12.0 low dropout voltage regulator. The ones I bought worked perfectly in my tests with my LEDs.

My LEDs use 20 to 40 mA each. I varied the voltage from 10.0 volts to 18.0 volts. Below 12.0 volts, the voltage out at the LED was the same as the input voltage. Above 12.0 volts the voltage stayed between 11.9 and 12.1 on my cheap multi-meter.

I used the LM2940 with no additional circuitry. Just soldered the input positive wire to Vin ground to GND of both the regulator and the LED and Vout to positive of the LED.

So far, so good.
My Chinese LED Light Tube with the LM2940 soldered inside the end. The legs straddling the end LED.

Sunday, September 20, 2015

NMEA WiFi Bridge


!! Software and library updates in github Jan 14, 2016 !!  

Updated Fritzing schematic Apr 28,16

 

The second strip-board version of my NMEA WiFi Bridge. On my boat and several others, we are running OpenCPN for navigation software. Most of us run it on a laptop. The common inputs are GPS, AIS and some have all their instruments connected as well; depth, wind, speed & distance log, etc.

There are two problems that I am trying to solve. First, too many cables to the laptop providing the instrument data. And second, a way to share the instrument data with multiple devices. The release of opencpn for android tablets and smart phones makes it feasible to have multiple displays around the boat. Like in the captain's bunk to check on crew without getting out of bed.

So this friend that wants all of the instrument data over the network has a multiplexer that takes his SeaTalk and various NMEA 0183 signals and outputs a higher baud NMEA sentence data stream. And I have a combination AIS/GPS that has NMEA 0183 at 38400 baud. My laptop is getting old and if you touch the USB cable from the RS-232-to-USB it disconnects and reconnects using a different port configuration.

And besides it would be nice to have no cables, especially to a phone or tablet.

Along comes the ESP8266 Serial WiFi module with a modest price around $2.50 USD and other board configurations for a few dollars more.

So the plan is to create new firmware for the module, connect the rs-232 based NMEA 0183 signals to it and broadcast the sentences over the WiFi as UDP packets on the local subnet. So this will require a WiFi Access-point (AP) on the boat. (ED. It may be possible for the ESP to be the router too.)  Another recent development is the availability of cheap pocket routers such as the TP-LINK WR702N. I picked mine up in Singapore for less than $8.00 USD last year, but the market is full of competitors.


The +5v power (from a 12v automobile USB charger module) comes in through the switch, upper left then a 3.3v regulator and then to the ESP module's socket. It is a little sensitive, so pull-up resistors are recommended on the 3 data lines, GPIO2 and Rx) and the chip select and reset pins. Tx and Rx are needed for programming (flashing) the firmware, and as a development board I chose to bring those to the top right pins with a ground for a future test of a 16x2 serial display. 

The NMEA 0183 from a Garmin and my AIS sort of conforms to rs-232, they are -2.9v to 2.9v. Therefore, after a little search, I found a single transistor level shifter for the Rx input to make it conform to the 3.3v TTL levels of the ESP module.

The LEDs and pins at the bottom show the state of the 2 GPIO lines. The software configuration technique uses a short between these to go into config mode. The push button puts the module in flash mode.


And the schematic of the first rev of the board. It is also the one in the fritzing project on my github site along with the code in C.



Figure 2. Schematic_v2


Parts List:
 1 - ESP8266-ESP-01
 1 - LD1117-33 regulator (any 3.3v > 500ma  will do)
 1 - 1uF tantilum
 6 - 4.7K ohm pullup resisters
 1 - 330 ohm current limit for Tx buffer
 1 - 10K ohm for rs232 level convert 1 - 2n2222 for level convert
 1 - 1N5819 program Rx input
 1 - LED
 3 - momentary pushbuttons


The design of the code has three parts.

First, short the two GPIO lines(press the config button) and turn on the power. After a few seconds (5-6)  the LED comes on indicting the module is ready to configure. It starts an AP at 10.1.1.1 that you can connect to with a WiFi capable device (laptop or phone or tablet using DHCP), then access the webpage at that IP. You get this page:






Enter the ssid and password for your boat network, the UDP port to connect and the baud rate to listen for the NMEA data.

When you click configure, it displays a confirmation of your data.
If it is correct, turn off the board, connect it to you NMEA data, remove the short between the GPIO pins and turn on the power.

The second part of the code now runs. It listens for NMEA sentences and when it has a complete sentence, broadcasts it to the broadcast address of the subnet you provided in config. All devices on that subnet can read these UDP packets.
Now go to your opencpn configuration settings, then connections. Add a new connection, selecting: network, UDP and the port number from above (default is 10110).
You should be getting data.

The third part consists of a status page. You can look in a web browser at the IP address of the NMEAWiFiBridge and get a status page that updates the number of sentences broadcast every 10 seconds. It may severely impact the ability of the ESP to keep up with a busy data stream to monitor it, so it is only there to help with trouble shooting the connections.



See my github repository for code and schematics. For faster communication, I can be contacted through my github profile (click on my user name).

The configuring software is based upon the work of Forward Computing and Control. My hardware is opensource, my software is GPL3.