Wednesday, March 22, 2017

Arduino ESP8266 WiFi, on the Cheap!

If you are looking for Wifi for for your Arduino Project, look no further! For less than $9 you can add wifi capability to your Arduino Project, without loading down your Arduino with a bunch of network access code. We used a HiLetgo New Version NodeMCU LUA WiFi Internet ESP8266 Development Board for the access link. Now this board has a bunch of 3.3v I/O capability all on it's own, and is easily programmed using the Arduino IDE, but our goal is to use a Arduino NANO for I/O and just use the ESP8266 for the network link.

Installation was not straightforward, but not difficult either. The board uses a standard USB A-Male to Micro B cable used with most cell phones. Plug the cable into the ESP8266 and your computer. If you are on Windows, check your device manager to see what port has been connected. If you have a yellow exclamation mark on the device (Silicon Labs CP210x), right click it and choose Update Driver Software.

Now open a recent version of the Arduino IDE (1.6.4 or greater). Under File - Preferences, add http://arduino.esp8266.com/stable/package_esp8266com_index.json to the Additional Boards Manager URLs field, and click OK.

Now go to Tools - Board - Boards Manager and scroll down to ESP8266. Select ESP8266 and click Install.

Now to use the board, Go to Tools - Board, and select the Adafruit HUZZAH ESP8266. Others may work better, but that's the one I started with.

Remember, this board uses 3.3v logic, so no 5v connections to the I/O pins.

The sample sketch I tried worked first time, and connected to the web server right away. See https://learn.adafruit.com/adafruit-huzzah-esp8266-breakout/using-arduino-ide for code.

Use the D0-D10 and A0 pins printed on the board the same as the pins on an arduino (given the 3.3v caution). The pinouts are below:


For a cool "Breathing" effect of the onboard LED at pin "0" (D0, or GPIO16), see https://arduining.com/2015/08/20/nodemcu-breathing-led-with-arduino-ide/

Wednesday, March 8, 2017

Encryption fun, win an Arduino!

Here's a challenge for you all. I'm posting a picture, and a coded phrase. Figure it out, email me, and the first 5 winners get an Arduino Nano clone, and their names (or hacker names) listed as really smart (and geeky) folks!

59221 91430 8117 94007 21268 100714 58135 73658 29992 52388 103243 47570 29961 38689 74327 56189 45120 64972 81138 106187 18809 11348 10965 32969 70849 96470 6350 56264 69516

After the contest is over, I'll post the code, and some really interesting tips on passing virtually unbreakable messages.

Clue: it's a variation on a book cipher!

Next Clue: the numbers above are the positions of the characters in the "book".

Solution:

The image is base64 encoded. That creates the book. Then go to position 59221 and write down the letter found, then position 91430 , and so on.

In the files below, I've built a php based set of utilities for choosing an image, saving it in an uploads folder, and creating the encoded ascii file. You then can input the string to be encoded, and it returns character positions from the "book".  I used a date/time seeded random function to choose one of the available results for each character submitted to reduce the possibility of repeat distribution hacking.

The decode file takes those position codes, and spits out the original phrase. No one has posted the phrase, but the contest is over. Hope you had fun!

https://drive.google.com/open?id=0ByRIq5k2wjcSbGVBaWc4bmFGN00

Tuesday, February 14, 2017

KK4HFJ HF Station is up and running!

I finally made the move from 2m EmComm's to HF work. I'm still working 2m off the local repeaters, but it's nice to be able to reach around the world. I installed a Kenwood TS-430 HF rig, a AT-250 Antenna Tuner, a MFJ G5RV dipole, and a dell server power supply to keep it all fed and quiet. You can find me most evenings on 40m, usually around 7.18 Mhz.

KK4HFJ Monitoring .....

Friday, January 27, 2017

STEMTera - Arduino in a LEGO Breadboard

Sparkfun is coming out with a new breadboard that includes a Arduino in a LEGO compatible base. All the ATmega328P and ATmega16U2’s I/O pins are broken out and available. The breadboard has shield compatible pinouts (yes, the weird offset is there). A bit more than you would pay for a Arduino UNO, but the convenience of having a breadboard and complete access to all the pins makes up for it. This is a perfect teaching tool!

https://www.sparkfun.com/products/14082


Tuesday, January 3, 2017

Model Railroad Crossing Lights

For the Charleston Area Model Railroad Club, We have combined our train detector circuit from the scale speedometer project with a LED Crossing Light to make it simple to indicate a train is coming to a crossing. The next step is to add a servo operated crossing bar, and bell sounds, but I'm getting ahead of myself.

The Circuit:
The detection circuit is the same as the scale speedometer. A TCRT5000 IR LED / Phototransistor pair, with two resistors, connected to an Arduino input (D8). You can lower the value of the Phototransistor pullup resistor to 10k-50k ohm (instead of 80k-100k ohm) to reduce it's sensitivity to ambient light. Increase the value of the IR LED resistor (68 Ohm) to reduce range. Never drop IR resistor below 68 Ohms.

The output is a off the shelf LED crossbuck with 2 red LED's and a common anode. I put a 300 ohm resistor on the common and connected to 5v, and connected the two cathodes directly to arduino outputs D11 and D12. Add a second LED Crossbuck (with resistor) to the same outputs for the other side of the crossing. See the video below the code.

The code checks to see if the phototransistor is lit (a 0 or LOW), and activates the lights (LOW is lit, HIGH is off)) as long as it is.


//int sensor1 = 1;


void setup() {
  Serial.begin(9600);
  pinMode(8, INPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(11, HIGH);
  digitalWrite(12, HIGH);

  int sensor1 = digitalRead(8);
  Serial.println(sensor1);
  if (sensor1 == LOW){
    digitalWrite(12, HIGH);
    digitalWrite(11, LOW);
    delay(1000);            
    digitalWrite(12, LOW);
    digitalWrite(11, HIGH);
    delay(1000);
  }
           
}


Finished board for two track sensors and 2 crossing lights.



Monday, January 2, 2017

Model Railroad Turnout Control - Arduino MOSFET

One of the projects we are working on is Turnout Control. Most home layouts are using Atlas or Bachmann track with solenoid type turnouts like the one shown here. More professional layouts use slow moving motors like the Tortoise. Our goal is to make these turnouts controllable with an arduino, so that future projects using train detectors and DCC can allow more automation. So here is the beginning of our project. This one uses the above Bachmann turnout (arduino servo control article coming soon), a arduino nano, two IRL520 MOSFETS, two resistors, and two diodes. The schematic is as follows:


The diodes protect the MOSFET from inductive spikes when the solenoid coils fire. The two MOSFETS engage the solenoid coils to move the turnout. the two resistors keep the MOSFET from randomly conducting when there's no input signal, by pulling the gate to ground (off). This uses two digital outputs on the arduino called straight and turn. The next article will show the board layout and wiring of the arduino, turnout and power supply. For more projects based on MOSFETS, see http://arduinotronics.blogspot.com/search?q=mosfet

Saturday, December 31, 2016

Arduino Cousins Rejoined in 1.8.0

The two forks of the Arduino IDE have been rejoined into one. No longer are there separate IDE's from Arduino.cc and Arduino.org. Boards from both companies and new additions from Adafruit are supported. This is great news for the Arduino Community. Requires Java 8 to run, but well worth the upgrade!


Arduino IDE 1.8.0 works out of the box with AVR boards, like the Uno, Mega, Yun, and Micro, among the most popular. Additionally, it supports the Leonardo Ethernet, Yun Mini, Industrial 101, and Uno WiFi.

The updated SAMD core will provide support for the M0 and M0 PRO, completing the product line that includes the Zero, MKR1000, and the newly-launched Primo and MKRZero.

Wednesday, December 28, 2016

The Pixel OS Controversy

There's been a lot of "news" about the Raspberry Pi Foundations new Pixel OS. Lets dig in and take a look at what the hubbub is all about.

First of all, contrary to much of the misinformation by the BBC, Guardian, and others, it's not an OS.

It's an alternative DE (Desktop Environment), much like gnome, LXDE, and others, that sits on top of a linux OS. That's it, nothing more.

As a DE, it's lightweight (needed for limited resource machines like the Raspberry Pi), and very pretty. It's fully available for the Raspberry Pi, or you You can download an image bundled with debian and try it in preview mode on a intel based pc. Preview mode? Yes, you cannot install it on your computer, as it's a "developmental beta", not an installable DE.

The good news? Eventually it will be a usable option not only on the Raspberry Pi, but other platforms like Intel based pc's. Eventually.

Monday, December 12, 2016

Arduino Model Railroad Animation

As part of my journey looking for new projects for the club layout, I just finished a book called Arduino Model Railroad Animation. It covers using servos to operate semaphores, water tank, cranes and other trackside accessories. This is a good practical guide to electro-mechanical automation using an Arduino as the brain. The authors (Paul and David Bradt) have a few other Arduino books as well that are equally good. We are working on a project using servos to actuate turnouts and microswitches.

Arduino Model Railroad Animation

Arduino Model Railroad Signals

Arduino Force, Pressure, Friction and Acceleration Science Fair Projects

Arduino Heat Transfer Science Fair Projects

Saturday, November 26, 2016

Arduino Model Railroad Scale Speedometer - Finished

We finally finished the Scale Speedometer Project, and are heading off to the Charleston Area Model Railroad Club to install it. We used the Adafruit I2C 7 Segment backpack, a Arduino Nano clone, and two IR transceivers, for  total project cost of around $20. The code below is fully functional, all you need to do is adjust your scale, and distance between the sensors. Make sure your sensors do not extend above the height of the rails, or couplers could catch on them. I used a dremel to route out the holes, and superglue to fix them in place, but superglue leaves a white residue, so you may want to try a different adhesive. Watch the video!

Arduino Nano Clone
7 Segment BackPack
IR sensors

Use the Adafruit Tutorial to assemble and connect your 7 segment backpack. Use the IR Sensor Tutorial to connect the IR sensors.

Update: Decreasing the resistance of the IR LED resistor (we finally used 100 Ohm) or increasing the resistance of the pullup resistor on the photo-transistor (we finally used 100k) can make the circuit more sensitive (up to 15mm depending on reflectance of car bottom), especially for larger scales with larger gaps. Do not burn out the IR LED with too low of a resistance (no less than 68 Ohm, 1/2w at 5v input).

#include  "Wire.h"
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"

Adafruit_7segment matrix = Adafruit_7segment();

//user variables
float distance = 24; //inches between sensors
int scale=87;

int sensor1 = 4;
int sensor2 = 5;
bool s1Covered;
bool s2Covered;
float start, finish, elapsed, miles, hours, mph, scaleMPH;

int started=0, finished=0;
int scale=87;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(sensor1, INPUT);
  pinMode(sensor2, INPUT);
  matrix.begin(0x70);

}

void loop() {
  // put your main code here, to run repeatedly:
  //Serial.println("Ready ....");
  matrix.print(0.0);
  matrix.writeDisplay();
    //finished=0;
    s1Covered=digitalRead(sensor1);
    if (s1Covered==0 && started==0){
      start=millis();
      started=1;
      Serial.println("Started");
   
    }
    s2Covered=digitalRead(sensor2);

    if (s2Covered==0 && started==1){
      finish=millis();
      finished=1;
      Serial.println("Finished");
   
  elapsed = finish-start; // millis

  elapsed = elapsed /1000; // seconds
  Serial.print("Seconds: ");
  Serial.println(elapsed);
  miles = distance / 63360; // miles
  hours = elapsed / 3600; // hours
  mph = miles / hours;
  scaleMPH = mph * scale;
  Serial.print("Scale MPH: ");
  Serial.println(scaleMPH);
 
  // print a floating point
  matrix.print(scaleMPH);
  matrix.writeDisplay();
  delay(25000);

  started=0;
  finished=0;
    }
  }


Friday, November 18, 2016

Functional TRS-80 Model 1 on Windows 10?


Ok, what does this have to do with Arduino or Raspberry Pi? Well, I am working on a couple of Pi emulating antique computer projects, and said, let's try this! I could use some financial help with a few projects we are working on, so use the "Donate" button found on this page, and I'll send you a zip file with a working TRS-80 Model 1 emulator (ROM included). Just unzip and run an old friend ....

Tuesday, November 15, 2016

Arduino Scale Speedometer Part 3 - Port Expander

The three 7 segment LED's from part 2 require 24 i/o pins on the Arduino. We can use port expanders to limit that to 2 pins, the I2c connections. Each MCP23017 chip supports 16 i/o pins, so two chips will do, and still only use the two lines on the Arduino, as they are addressable. In our previous two MCP23017 posts we show how to connect and address the MCP23017 chips and provide a link to the datasheet.

1st Digit - Chip 1 Port A Connections:
GPA7 -> A7
GPA6 -> B6
GPA5 -> C4
GPA4 -> D2
GPA3 -> E1
GPA2 -> F9
GPA1 -> G10
GPA0 -> DP5

2nd Digit - Chip 1 Port B Connections:
GPB7 -> A7
GPB6 -> B6
GPB5 -> C4
GPB4 -> D2
GPB3 -> E1
GPB2 -> F9
GPB1 -> G10
GPB0 -> DP5

3rd Digit - Chip 2 Port A Connections:
GPA7 -> A7
GPA6 -> B6
GPA5 -> C4
GPA4 -> D2
GPA3 -> E1
GPA2 -> F9
GPA1 -> G10
GPA0 -> DP5



To send the speed determined in part 1 to the 3 digit display, we need to break up the number into 3 separate numbers, the hundreds, tens, and ones position. This is done with a simple calculation:

first=number/100;
second=number%100/10;
third=number%10;

Then in a case statement you can send the correct code to each chip:

switch (var) {
    case 0:
      Wire.write(244); //11110100
      break;
    case 1:
      Wire.write(96); //01100000
      break;
    case 2:
      Wire.write(218); //11011010
      break;
    case 3:
      Wire.write(242); //11110010
      break;
    case 4:
      Wire.write(102); //01100110
      break;
    case 5:
      Wire.write(182); //10110110
      break;
    case 6:
      Wire.write(190); //10111110
      break;
    case 7:
      Wire.write(224); //11100000
      break;
    case 8:
      Wire.write(254); //11111110
      break;
    case 9:
      Wire.write(230); //11100110
      break;
    case DP:
      Wire.write(1); //00000001
      break;
    default:
      // if nothing else matches, do the default
      // default is optional
    break;
  }

Now, if all this seems very complicated, and the 24 wires from the 3 digits to the two MCP23017 chips seems like spaghetti, you are right, and we have chosen to go a different path. The Adafruit I2C 4 digit display. More on that tomorrow .....

Monday, November 14, 2016

Arduino Scale Speedometer Part 2 - 7 Segment LED's

In part two (see part 1 for the train detection circuit) we are addressing the three 7 segment displays. We are using Common Anode displays, so we send a low to each segment to light them up. Use whatever you have available, and use the data sheet for your displays and map accordingly.


 This image shows each segment, and assigns a letter to each, to help with the wiring.






The next image shows the pin numbers and positions looking at the face of the display.

Now we show which segment is assigned to which pin, and the polarity of the pins. Since we are using Common Anode, the LED symbols point down,or away from the common positive (5v) signal (pins 3 & 8). A LOW is sent to each pin to light up the associated segment. If you are using Common Cathode, then the diodes would point up, 3 & 8 would connect to ground, and a HIGH would be sent to each segment to light them.

As is the case with all LED's, a current limiting resistor is needed to prevent the LED from burning out. The one you pick is dependent upon your source voltage, and the LED. We are using 400 Ohm resistors for this project.

The next post will address using a I2C port expander to free up the 24 pins the display uses.

Sunday, November 6, 2016

Arduino Model Railroading - Scale Speedometer

The guys at the Model Railroad Club wanted a scale speedometer displaying the scale speed of the train as it passes a point on the layout. I'm using two IR transceivers connected to an arduino to detect the time it takes to pass between 2 points, and then displaying the scale speed.

Currently we are using the Serial Monitor, but Part 2 will be about the 3 seven segment display and I2C port expander used to drive them.



Wiring:
The circuit diagram is the same as the one we posted here, but just doubled.

Code:

int sensor1 = 4;
int sensor2 = 5;
bool s1Covered;
bool s2Covered;
float start, finish, elapsed, miles, hours, mph, scaleMPH;
float distance = 24; //inches between sensors
int started=0, finished=0;
int scale=87;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(sensor1, INPUT);
  pinMode(sensor2, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:

    //finished=0;
    s1Covered=digitalRead(sensor1);
    if (s1Covered==0 && started==0){
      start=millis();
      started=1;
      Serial.println("Started");
    }
    s2Covered=digitalRead(sensor2);

    if (s2Covered==0 && started==1){
      finish=millis();
      finished=1;
      Serial.println("Finished");
   
  elapsed = finish-start; // millis

  elapsed = elapsed /1000; // seconds
  Serial.print("Seconds: ");
  Serial.println(elapsed);
  miles = distance / 63360; // miles
  hours = elapsed / 3600; // hours
  mph = miles / hours;
  scaleMPH = mph * scale;
  Serial.print("Scale MPH: ");
  Serial.println(scaleMPH);
  started=0;
  finished=0;
    }
  }




Saturday, November 5, 2016

Arduino Model Railroading - Simulated Flickering Fire

Another cool exhibit on your model railroad is flickering firelight. Whether it's a hobo campfire, or a burning building, this adds to the layout's realism. A Arduino, 3 130 ohm resistors, two yellow LEDs, one red LED, and you have a fire. Add a locomotive smoke unit for additional realism. This project is provided by Mike McRoberts.


Just connect a wire from pin 9 to the resistor, from the resistor to the long leg (+) of your LED, and the short leg to Ground. Repeat for pins 10 & 11. We put the red LED on pin 10, and the 2 yellows on 9 & 11.
Code:

// LED Fire Effect

int ledPin1 = 10;
int ledPin2 = 9;
int ledPin3 = 11;

void setup()
{
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
}

void loop() {
analogWrite(ledPin1, random(120)+135);
analogWrite(ledPin2, random(120)+135);
analogWrite(ledPin3, random(120)+135);
delay(random(100));
}