Wednesday, June 20, 2018

The ESP8266 doesn't have EEPROM?

Unlike the Arduino AVR based controllers, the ESP8266 does not have a dedicated EEPROM. We can however use a bit of flash memory as a emulated EEPROM, and we can use the Arduino EEPROM library to do it. Using the Arduino Put and Get code samples as they are doesn't work. However a simple

EEPROM.begin(1024); // both the put and get code

before the

EEPROM.put(address, variable);
or
EEPROM.get(address, variable);


and a

EEPROM.commit(); // only on the put code

after it makes everything work.

In the linked code samples below, I'm saving 2 strings of text (wifi ssid and password) to the EEPROM in the put code, and retrieving them in the get code. If you put a slide switch in your project, and run the two pieces of code depending on the switch position, you can reset the credentials from a built in web form. I will cover that ability soon.

ESP8266 EEPROM "PUT"

ESP8266 EEPROM "GET"

Fore more info, see:
http://esp8266.github.io/Arduino/versions/2.0.0/doc/libraries.html#eeprom

https://www.baldengineer.com/arduino-eeprom-stores-any-datatype.html

APRS Transmitter

The HX1 is a low-power amateur radio transmitter set to a fixed frequency of 144.390 MHz. In North America, this frequency is used for the Automatic Packet Reporting System, or APRS

APRS is a standard used by amateur-radio operators to broadcast live sensor data on a shared frequency. This data can be received by anyone with the proper equipment, and is aggregated on the internet through gateways run by members of the APRS community. APRS is commonly used to share real-time data including vehicle location (GPS), weather stations, high-altitude balloon tracking, remote sensor platforms, disaster relief coordination, and more. It’s effectively an open-source, open-data, community-run, free to use, IoT system with potentially worldwide coverage.

The HX1 is a 5V, low-power (300mW), narrowband (3kHz) VHF FM transmitter module. With a simple antenna, the range will be around 6 miles. Since this is a “bare” transmitter, the data input must be properly modulated and formatted. There are several Arduino software packages that can do this, see the hookup guide for information.

Note: Because it uses amateur radio frequencies, you will need an amateur radio license to use the HX1. It’s easy (and fun!) to get one.

Tuesday, June 5, 2018

Arduino connected Micro Epsilon Laser Micrometer

With the success of our Igaging / Mitutoyo and Harbor Freight digital measuring devices projects, now it's time to turn our attention to the Micro-Epsilon Laser Micrometer, optoCONTROL 2600.

There are several types of outputs, including analog, digital RS-232 and RS-422, and Binary or ASCII options. We chose ASCII on the RS-422 output (9600, 8N1), and connected a RS-422 to TTL converter to a Arduino Nano clone using SoftSerial. Wiring is as follows:

Micro Epsilon DB25:
Pin 8 (Tx-) to RS-422 R+ //inverted data
Pin 7 (Rx-) to RS-422 T-
Pin 20 (Rx+) to RS-422 T+
Pin 21 (Tx+) to RS-422 R- //inverted data
Pin 22 (gnd) to RS-422 gnd

RS422:
VCC to Arduino +5v
Gnd to Arduino Gnd
Tx to Arduino D4 (Rx) // now Serial1 Rx
Rx to Arduino D3 (Tx) // now Serial1 Tx

Follow along at the Arduino Forum as we attempt to decode the data from this gadget!

UPDATE: We have switched to a MEGA2560 with it's hardware UART's, instead of using the Nano and SoftSerial. This allows faster data acquisition.

Friday, May 18, 2018

RPM into MPH? Building a Anemometer!

I'm building an anemometer to measure wind speed. I'm building the typical 3 cup style anemometer, and using a hall effect sensor (digital, non-latching) to trigger an arduino (or esp8266).

It's a open collector unit (output pulls low when triggered with a magnet), and therefore uses a 10k ohm pull up resistor, or use

pinMode(inPin, INPUT_PULLUP);

val = digitalRead(inPin); // read the input pin

and watch for a LOW (FALLING when using interrupts - https://playground.arduino.cc/Main/ReadingRPM)


Inside the unit, I want to pass a small magnet across the sensor. I could use 1 or more magnets, and adjust the code for the number of pulses (triggers) per revolution. Let's assume 1 magnet, so one pulse per revolution.

The math looks like this:

RPM = cycles per second (Hz) * 60 seconds per minute / # of magnets

(to count cycles per second or HZ - https://circuitdigest.com/microcontroller-projects/arduino-frequency-counter-circuit)

FPM = RPM * Diameter (inches) / 12 * 𝝅

FPH = FPM * 60

MPH = FPM / 5280

Where:
RPM = Revolutions Per Minute
FPM = Feet Per Minute
FPH = Feet Per Hour
MPH = Miles Per Hour
𝝅 = 3.14 (pi)
Diameter = inches from center of shaft to center of cup * 2

More on this to come.

Thursday, April 26, 2018

The Arduino 18650 Lithium Ion Battery Charger

The 18650 Lithium Ion Battery is becoming the go to battery for rechargeable projects, from microcontrollers to skateboards and ebikes.

We have been powering our Raspberry Pi, Arduino, and Ham Radio projects with them.

Although soldering the tabs on these batteries have been difficult (and damaging) in the past, there are now solderless interlocking kits that make them very easy to use.

It's extremely important to make sure these batteries are charged properly! Henry's Bench comes to the rescue with a Arduino controlled charger for these batteries. Just add a LCD screen to see voltage, amps, and cell temperatures.



Explanation of Lithium Ion charging profiles and dangers - http://batteryuniversity.com/learn/article/charging_lithium_ion_batteries

To learn more about building battery packs with the 18650, the master tome of all info is DIY Lithium Batteries (How to build your own battery packs), by Micah Toll (subscribe to his YouTube channel).





Tuesday, April 17, 2018

Adding a LCD to a ESP8266

Tutorials for adding a LCD to a Arduino are all over the net. It's pretty simple, and I2C makes the wiring even simpler, and libraries prevent complicating the code much. However, adding a LCD to a ESP8266 is not as common, and there is much misinformation posted about logic levels, and what not. So here is a working project using a I2C LCD, and a ESP8266. Wiring is very simple.

SCL to SCL
SDA to SDA
(these two pins are redirectable to another set in the Wire.begin command:

//Wire.begin(); default
Wire.begin(0, 2); // specified SDA, SCL pins

Gnd to Gnd
+5v to +5v (USB or Vin)

Yes, the LCD prefers 5v, and it won't affect the 3.3v logic of the ESP8266, as the ESP8266 I2C is in output, not input mode.

Some slower I2C devices won't work out of the box with the ESP8266 because of timing issues, and a stretch adjustment needs to be made. We found one I2C display that would not register on the I2C scanner sketch, but the rest did. If the scanner finds it when connected to a UNO, but not a ESP8266, place the following command after the Wire.begin line.

Wire.setClockStretchLimit(500L);

Make sure you run the I2C scanner first, to check what I2C address your display uses. See more in our Instructable at https://www.instructables.com/id/I2C-LCD-ESP8266/

If you don't have one already installed, you will need to install a I2C LCD Library. Those instructions are included in the Instructable.

Saturday, March 31, 2018

Controlling a ESP8266 with Alexa

Here is an easy project using a Echo Dot (Alexa) to control my ESP8266. I give it simple commands (Alexa, lights, off) and the command shows on the LCD screen attached to the ESP8266. Actual relays will be the next step to attach.

The project is based on the Adafruit tutorial at https://learn.adafruit.com/easy-alexa-or-echo-control-of-your-esp8266-huzzah/overview

with LCD and other modifications made by me. My code is found at https://pastebin.com/NjMcsTRh

Also see my ESP8266 LCD Project at https://www.instructables.com/id/I2C-LCD-ESP8266/



Friday, February 23, 2018

5mm LED Holders

One of the things I find myself making often, is plastic (plexiglass) control panels. I still have not made my desktop cnc yet, but when I do, I can stop drilling these panels by hand. Mounting LED's is always a task, and I started using these very nice chrome LED holders. They come with a plastic plug for the 2 LED leads to stick through, and hold the LED securely. For my 4 lead RGB LED's, I just use a spot of hot glue to hold the LED, and heat shrink tubing to insulate the leads. Use a silicone coated wire for flexibility and stress relief.

http://amzn.to/2op7MGL




Tuesday, February 20, 2018

FreePBX - Open Source PBX Phone System

I just installed FreePBX, a linux based open source phone system at work (12 SIP trunks, 40 extensions), and thought, why not a home / small office unit based on a Raspberry Pi? The Raspberry Pi can easily handle multiple SIP trunks, and enough IP phones for the whole family / small business to have a extension or even a private DID. The FreePBX software is free, the Raspberry Pi is inexpensive (about $80 for a complete kit) and PolyCom IP Phones are readily available for around $80 each. Now you can have individual voicemail (email integrated), auto attendant, intercom, paging / bells, and music on hold just like the big boys. The phones and paging adapter can be powered by a inexpensive POE network switch, as can the Raspberry Pi with a POE Hat.

Arduino integration? Yes your Arduino can make outbound calls with prerecorded alerts!

Thursday, January 11, 2018

ATX Bench Power Supply

As a Ham Radio operator and a electronics / programming fanatic, I'm always on the lookout to improve my bench equipment. This weeks upgrade is a multi voltage bench power supply. For those that have been looking, bench power supplies can be very pricey, but many people overlook the ubiquitous computer power supply. It has +12v, -12v, 5v, and 3.3v taps, but not in a easy to use form. That changes with a ATX power adapter. Now you can easily add a variety of voltages to your projects, in some hefty current ratings, up to 36 amps or more.

The next stage is to add a Arduino voltage and current display for each output, and maybe some MOSFET's for adjustable output for testing motor speed.

ATX Power Supply $22

ATX Power Distribution Board $30
includes solderless breadboard and breadboard power supply adapter. 

See http://www.electronics-tutorials.ws/blog/convert-atx-psu-to-bench-supply.html for notes on cooling, regulation, and other voltage combinations.

Friday, December 29, 2017

Raspberry Pi and a UPS (Battery Backup)

Regular workstations (PC's) and servers are often plugged into a UPS (Uninterruptible Power Supply, or Battery Backup) with a USB cable so that the UPS can tell the computer when battery voltage is low, and to perform a clean shutdown.

A Raspberry Pi does not come with a power switch. If you were to cut power without running a proper shutdown command, you can easily corrupt the SD Card.

We can do the same with a Raspberry Pi. The following site outlines the procedure for setting up the monitoring software so that your Raspberry Pi will properly shutdown when the backup battery gets low. If you have several Raspberry Pi's, they all can get the shutdown command from the same UPS.

https://melgrubb.com/2016/12/11/rphs-v2-ups/

We use the CyberPower 750 shown. A Raspberry Pi can run for weeks before the battery runs low.

http://amzn.to/2CldWQe

No more corrupted SD Cards, and no more worries!

Alternate method using APCUPSD - https://www.raspberrypi.org/forums/viewtopic.php?t=14447

Tuesday, December 26, 2017

Harbor Freight / Pittsburgh Caliper Arduino Connection

Another HF Caliper project. Here is the HF Caliper connected to our digital interface for Arduino, Raspberry Pi, and more. Just above the battery door is a small access panel that covers a 4 pin edge connector. Carefully solder 3 wires to those pads, which, from left to right are GND, Data, Clock, and +1.5v (we aren't using that one). You no longer need to solder on to those delicate pads, as we have a cable that plugs right in!

The interface is simple. two transistors (we used 2N2222A) and four 10k Ohm resistors 1/4w.

You can order a finished board for only $20, a HF cable (no soldering) for $25, and a Arduino Nano w/ integrated Screw Shield for $15

Screenshot, schematic, and code are posted below. Thanks to the following sites for ideas and resources:

http://www.instructables.com/id/Reading-Digital-Callipers-with-an-Arduino-USB/

http://www.makingstuff.info/Projects/Digital_Calipers

Cable to fit caliper, eliminates need to solder - https://littlemachineshop.com/products/product_view.php?ProductID=3483&category=132430212

Just cut off the RJ-11 plug, strip 1" of the black outer jacket, strip 1/2" of insulation on each wire, fold back in half, solder, and insert into screw terminals (the wires are too fine to hold in the screw terminals otherwise). Connect as follows:

Gnd - yellow
Data - blue
Clock - red
1.5v (not used) - white

Next version of the board will have a RJ-11 jack on board, no stripping wires.








Arduino code is below:

//Digital caliper code to read the value off of a cheap set of digital calipers
//By Making Stuff Youtube channel https://www.youtube.com/c/makingstuff
//This code is open source and in the public domain.

const byte clockPin = 2;  //attach to clock pin on calipers
const byte dataPin = 3; //attach to data pin on calipers

//Milliseconds to wait until starting a new value
//This can be a different value depending on which flavor caliper you are using.
const int cycleTime = 32; 

unsigned volatile int clockFlag = 0; 

long now = 0;
long lastInterrupt = 0;
long value = 0;

float finalValue = 0;
float previousValue = 0;

int newValue = 0;
int sign = 1;
int currentBit = 1;

void setup() {
  Serial.begin(115200);

  pinMode(clockPin, INPUT);  
  pinMode(dataPin, INPUT); 
  
  
  //We have to take the value on the RISING edge instead of FALLING
  //because it is possible that the first bit will be missed and this
  //causes the value to be off by .01mm.
  attachInterrupt(digitalPinToInterrupt(clockPin), clockISR, RISING);
}

void loop() {  
  
  if(newValue) 
  {
   if(finalValue != previousValue) {
     previousValue = finalValue;
     Serial.println(finalValue,2);     
   }
   newValue = 0;
  }
  
 //The ISR Can't handle the arduino command millis()
 //because it uses interrupts to count. The ISR will 
 //set the clockFlag and the clockFlag will trigger 
 //a call the decode routine outside of an ISR.
 if(clockFlag == 1)
 {
  clockFlag = 0;
  decode();
 } 
  
}

void decode(){
   unsigned char dataIn;
   dataIn = digitalRead(dataPin); 
   
   now = millis();
   
   if((now - lastInterrupt) > cycleTime)
   {
     finalValue = (value * sign) / 100.00;
     currentBit = 0;
     value = 0;
     sign = 1;
     newValue = 1;      
   } 
   else if (currentBit < 16 )
   {
      
     if (dataIn == 0)
     {
       if (currentBit < 16) {
          value |= 1 << currentBit;
       }  
       else if (currentBit == 20) {
          sign = -1;
       }
               
     }
     
     currentBit++;
     
   }
   
   lastInterrupt = now;
   
}

void clockISR(){
 clockFlag = 1; 
}







Thursday, December 14, 2017

What is my Ultimate Raspberry Pi Station?

As I'm working on several Raspberry Pi hosted web/database/IOT projects this Christmas Season, I wanted to share my ultimate workstation.

First of all you need a Raspberry Pi. Now that version 3 is out, I got rid of all my older units and replaced them with this little wonder computer. The integrated WiFi and Bluetooth, plus the faster speed makes a useful computer into a absolute necessity!

I start with this Raspberry Pi Starter Kit which includes the Raspberry Pi 3, a 32gb SD Card, Power supply, and a HDMI cable.



Now, the case that comes in the kit is a fine case, but I wanted to mount mine on the back of my TV to keep it and the wiring out of the way. This VESA case can also mount on a wall or under a shelf.



Again, with the minimal wiring goal, I use a Logitech wireless keyboard / mouse combo.



And did I mention I use a TV? Yes! A inexpensive HD LCD with a HDMI input for the Pi, and I can still catch a game or movie when I need a break from programming!


Last, but not least, you may need a VESA hardware kit to fit your tv. This kit covers most TV models and will make it easy to mount your Pi on the rear of the TV.


So that's my setup, What is your preferred setup?






Tuesday, November 21, 2017

Arduino and Raspberry Pi Holder

When you are building circuits and programming your microcontroller, you probably have it sitting on a table, wires going everywhere, and possibly shorting the bottom pins on clipped wire pieces, tools, and other obstructions. It can be a challenge to keep everything tidy and organized, which can cause trouble shooting issues. I'm looking forward to my new organizer coming this week, and I will post video of it in use. It allows me to keep a Raspberry Pi, Arduino, and a breadboard stable and secure. Projects have a higher possibility of working the first time, as I can see better if wires are going where they are supposed to, and have not pulled loose!

Arduino / Pi / Breadboard Base



Here I have my Raspberry Pi 3, a Sainsmart Arduino UNO, and a Arduino WiFi / SD Card Shield mounted with a breadboard and a RPi I/O breakout adapter. A great setup for Linux, Apache, mySQL and PHP (LAMP) database storage and web presentation of Arduino connected sensors. I combined this with a CanaKit Raspberry Pi Starter Kit.

Wednesday, November 15, 2017

Model Railroad DCC Control - JMRI / Raspberry PI

For those who want to control their DCC Model Railroad with their cell phones or tablets (pretty much any Android (Engine Driver) or IOS (WiThrottle) device), There is a Raspberry Pi image already built. Copy it to a sdcard, insert into your Raspberry Pi, and you are pretty much set to go!

Once you've assembled the hardware and installed the image, connect your RPi to your layout via PR3, LocoBuffer-USB, NCE Serial, NCE USB, SPROG or DCC++, and plug in the RPi's power adapter.  You should see some LEDs on the RPi begin to blink, and shortly, using your wifi-capable phone, you'll see a WiFi network named "RPi-JMRI".  Select it and enter "rpI-jmri" when prompted for the key (note that 3rd character is a capital "eye").  Open EngineDriver on your phone, and you should have an available connection under Discovered Servers called "RPi-JMRI".  (Similar with WiThrottle on iPhone).  Enter loco address and run trains!

Related Posts Plugin for WordPress, Blogger...