Tuesday, November 8, 2016

Arduino for dummies

Ok, this is not a class on how to Arduino...this is a dummy (me) using an Arduino.

For the record...I am not uneducated about computers and programming...however, I know nothing about the Arduino...

I do know a bit about circuits.  I did learn Basic, Pascal, and Fortran77 in college.   I haven't programmed anything more complex than an Excel table lookup since college.  (and if you know how long it has been since colleges taught Fortran77...)  (The computer lab we had used one of these... Burroughs B6700)

I was always curious about the Arduino and the other small computers...but you have to have a need before you can motivate yourself to learn...well me anyway.

Good links

Circuits.io
arduino.cc
diyhacking.com
adafruit.com

Here was the 'need'.  We have a couple of 6' tall animatronic monster Halloween decorations.  They have some built in sounds and movements.   They can be triggered by a noise, or a button on the base.



It takes a sharp clap sound to activate the noise trigger...but I wanted something more controllable...and more automated.  For a few years I simply had about 20' of wire from the monster tapped into the switch in the base, and the other end was bare wires...I couldn't be bothered to solder a button in (5 year proof of concept test...)

I finally decided that I wanted the monster to be motion activated, as well as having the button trigger if necessary.   The problem with the button trigger is if you trigger it while it is doing its thing, the event will stop.   Some events are only 15 sec long or so, but one is 65 seconds (It sings and dances to Monster Mash)...I don't want to accidentally cut out the event.

So here is where the Arduino comes in.  I was sure I could create some trigger inputs, a relay output, and a self timer.




Here is the display when triggered.





Here is the display when timer is done.





Here is the circuit as viewed on circuits.io   The resistors connected to the LCD and the LED are 220ohm   The one connected to the pushbutton is a 10k, the potentiometer is 10k.  I put 9v into the Arduino and use the 5v from the Arduino.  The PIR (infrared motion detector) that I bought from Adafruit has a different pinout...but the Data goes to pin 6 and the other two pins are power.





And here is the code in all its glory...if you paste this into circuits.io, and wire up the circuit as shown, it will work.  (note, the upper left power leads come from a 9V battery...on the actual Arduino I have it plugged into the power jack)   (could the code be written better...duh) (oh, and this code works, but there are some edits I have since made to make the display look better...)  (BTW the screenshot of the circuit shows an additional switch to continuously activate the trigger...If I implement this in the hardware, then at the end of the timer, it will automatically start again.)


// include the library code
#include

// initalize the library with the numbers of the interface pins
LiquidCrystal lcd(12,11,5,4,3,2);

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int relay = 8;
int button = 7; // switch is on pin2
int buttonValue = 0; //switch defaults to 0 or LOW
int inputPin = 6;   // choose the input pin (for PIR sensor)
int pirState = LOW;  // we start, assuming no motion detecte
int val = 0;         // variable for reading the pin status
  
int runTimer = 1;
int runFor = 3; // time in seconds
int data = 0;

// the setup routine runs once when you press reset:
void setup() {
  // set up the LCDs colums and rows
  lcd.begin(16,2);
  //print message to LCD
  lcd.print("It's Alive!");

  // initialize the digital pin as an output.
  pinMode(relay, OUTPUT);
  pinMode(button, INPUT);
  pinMode(inputPin, INPUT);     // declare sensor as input
  
  
}

// the loop routine runs over and over again forever:
void loop(){
  //read the value of the button
  buttonValue = digitalRead(button);
  
  // if switch is HIGH - pushed down- change the lights
  if (buttonValue==HIGH){
    
    //changeLights();
    activateMonster();
    
       
    // coundown timer 
    if(runTimer == 1){ 
          lcd.clear();
          lcd.print("TIMER=");
          //Start timer
          timer(); 
       } else {
       }
       runTimer = 0;
       lcd.noDisplay();
       delay(250);
       for(int duration = 0; duration < 100; duration ++){
       } 
       lcd.display();
       delay(250);
       lcd.clear();
       lcd.print("Ready");
       runTimer = 1;
    } // end of coundown timer
  
  // now check PIR
   val = digitalRead(inputPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    
    if (pirState == LOW) {
      // we have just turned on
       lcd.setCursor(0, 1);
      lcd.print("Motion detected!");
       lcd.setCursor(0, 0);
      // We only want to print on the output change, not state
      pirState = HIGH;
                         activateMonster();
      // coundown timer 
    if(runTimer == 1){ 
         // lcd.clear();
          lcd.print("TIMER=");
          //Start timer
          timer(); 
       } else {
       }
       runTimer = 0;
       lcd.noDisplay();
       delay(250);
       for(int duration = 0; duration < 100; duration ++){
       } 
       lcd.display();
       delay(250);
       lcd.clear();
       lcd.print("Ready");
       runTimer = 1;
    } // end of coundown timer
      
    
  } else {
    
    if (pirState == HIGH){
      // we have just turned of
       lcd.setCursor(0, 1);
      lcd.print("Motion ended!");
       lcd.setCursor(0, 0);
      // We only want to print on the output change, not state
      pirState = LOW;
    }
  }         
 }  // end check switch loop

    //timer funtion
    void timer() {
       for(int timer = runFor;timer > 0; --timer){
       if(timer >= 10) {
          lcd.setCursor(6,0); 
       } else {   
          lcd.setCursor(6,0);
          lcd.print("0");
          lcd.setCursor(7,0);
       }
       lcd.print(timer);
       lcd.print(" SEC");
       delay(1000);
       lcd.setCursor(0,0);
       
    }  //end of void timer 
}  // end void loop


void activateMonster(){
  // turn relay on for 0.25 sec 
  digitalWrite(relay,HIGH);
  lcd.clear();
  lcd.print("FIRE!");
  delay(250);
  digitalWrite(relay,LOW);
}  // end of void activatemonster

Thursday, October 6, 2016

Wireless Previews from Canon (or other digital) camera to iOS, Android, or PC using a TP-Link portable router.---BIG UPDATE

For those new to the subject...I recommend looking at my post from 3 Jan 2014, and all the links.

Summary is if you get a TP-Link MR3040 battery powered wireless router (the size of an iPhone 4) put DD-WRT on it with some custom software, plug in your DSLR, drop an app on your mobile device, you can get live photo feeds, or actually control the camera.


The BIG UPDATE is how you actually install the software to the router...previously it involved doing quite a bit of command line editing through the router...just a pain.

NOW it involves a couple of firmware updates on the router, first using the router's web based interface, then after the first update, using DD-WRT's web based interface.

Here is the German article I used (via Google Translate)...I will edit it for clarity.

http://www.fotopxl.de/blog/wlan-router-dslrdashboard-shuttersnitch.html


Below is the cut and paste from that webpage, with my editing of the instructions for clarity.

This assumes a default install of the TP-Link software.

instructions 

  1. Download ar71xx.zip  http://www.fotopxl.de/download/ar71xx.zip
  2. Unzip file, you will have 5 items the md5sums, and two V1 firmwares, two V2 firmwares
  3. Use external power supply and battery to power TP-Link during this update.
  4. Connect the TP-Link with a network cable to your computer
  5. If your computer has DHCP set on network, you can immediately log in...if not change your computers IP address to 192.168.0.100, and default gateway to 192.168.0.1
  6. Log into TP-Link using default login admin/admin at address 192.168.0.1
  7. Go to Update Firmware
  8. Now select one of the previous downloaded firmwares... choose the correct version and  "-factory"   In my case it was            openwrt-ar71xx-generic-tl-mr3040-v2-squashfs-factory.bin
  9. After the install, the router will reboot...now it will be default DD-WRT and router will have 192.168.1.1  So change your computer address accordingly.
  10. Log into 192.168.1.1 default login root/root
  11. this is a good time to change the password.
  12. Now go to firmware update  http://www.fotopxl.de/images/blog/anleitungen/flash-image.jpg
  13. here you can still backup from the current state to make "Generate archive"
  14. Right now DD-WRT is running in default mode...so choose the other firmware  the one that ends in "-sysupgrade" openwrt-ar71xx-generic-tl-mr3040-v2-squashfs-sysupgrade.bin
  15. Now go back to the browser and selects "flash new firmware image" file above and click "Flash image" (see picture)
  16. follow the installation instructions
  17. It will reboot again, the browser should refresh automatically
  18. now there is a new tab "Transmitter" including finds her "WFT-Config"
  19. Here you have to still your password ShutterSnitch enter (see picture) , you should still do not have one, then now defines one and then give this at ShutterSnitch "Options" Change "password / create" a. This is the same password for your superuser ShutterSnitch.
Done! In order to use both programs, you must use the switch on the right side and adjust the position, which is required for the program.
3G / 4G = nothing 
WISP = wf-transmitter (ShutterSnitch)
AP = ddserver (DslrDashboard)
Thus, you can switch between the programs and use both. Thank you for the excellent work.

That is much easier than the old way...On my Canon 60D I have ShutterSnitch working...but haven't yet gotten DSLRDashboard to work.

Friday, June 3, 2016

Readynas NV+ errors (LED lights) and how I fixed it.

Usually the Readynas is good at letting you know when something is failing...I didn't catch it this time.

I have two of these, one has documents and photos in a RAID5 configuration (you give up about a drive worth of data for redundancy...lose one drive and it will rebuild the data).  Of course a RAID is not a good backup, so I have a USB drive plugged into it that takes a backup of the RAID, and the most important things are also backed up to the cloud.

The second Readynas NV+ is set up in their RAID-X configuration, which is sort of like a RAID5 but you can add drives to increase the size.  I use that one for media, audio and video,

Both NASs are plugged into a UPS, but only one is connected electronically to the UPS to get autoshutdown alerts...so the second one, when the power was out for a long time, was basically unplugged.

When I went to power them up, the first one booted up fine, the media one did not.

The problem...

The biggest issue with this smart NAS is unless it boots up completely, you have to guess what is wrong.


So the second one booted up with the LCD dark and blank, the LEDs for Drive 1 and 3 on...and nothing else...great.

Looking it up, those LEDs indicate the RAM is bad...I had put a 1gig ram into it replacing a 512meg one...I pulled the 1gig ram and put in the 512m ram...now when I try to boot it said something about OS not found...

...great...more googling later and I find that I need to do a USB OS install...You download the USB OS install firmware from Netgear (you have to know what version etc...luckily I knew I had the latest...see previous post about these drives).

I put the stuff on the USB thumb drive, put it in the slot and boot (instructions at Netgear, or here)

It get going along installing...and stops at drive 3...just kind of quits...no error message, but Drive 3 LED is flashing.  Drive 1 and 2 are on steady.

At this point I assume that drive 3 is bad...so I put a spare drive in (I keep a qualified, unused spare drive in case I get a drive failure like this...usually I can keep using the old drive somewhere else)

I try again with brand new -virgin out of the sealed antistatic bag- drive...I get the same exact result.

Well luckily they still sell the RAM, so I got on Amazon and ordered a replacement (using the part number off the 1gig ram I pulled.   Meanwhile I ran a ram test using the NAS (it has some self test capability even when it won't boot)  512M ram was bad also apparently....great

New ram comes a week later...I pop it in, do the USB OS install...this time that is successful, so I go for a boot...LCD says "Booting..." Drives 1,2,4 are on steady, drive 3 is flashing.

Remember that I have the new virgin drive in the #3 slot...ok I put the old drive back in...no change.

Now after another few hours of googling, I find that I now need to do an OS reinstall...I did a USB OS install, but that only get loaded to the NAS...I guess the OS Reinstall moved the OS from the NAS to the drives themselves...or something like that.


Success!   Now it boots properly, LCD shows the drive info and IP address.   I go to log in using the web console...won't log in...bad password...great.

So apparently when you do these type of USB OS installs or maybe the OS reinstall, the login goes back to default...well for the older OSs it is admin/infrant1   ... the newer ones use admin/netgear1  ... other new versions use admin/password.    So I tried them all, but mine had defaulted to  admin/netgear1

Now I can finally view what the heck is going on...meanwhile while I was trying to figure out the password, I ran the RAIDar.exe  (a piece of software from Netgear that allows initial admin of NAS before they are set up)  It showed the problem NAS and said that drive 3 was bad.

So I was right, the #3 drive was bad...but why didn't putting in the new drive fix that?

My guess is that the last status of the system was that drive#3 was bad, and it kept that status stored on the RAID itself...so until the RAID gets fixed with a new synced drive...the light will flash.


So right now the NAS has resynced about 26% of the data...only 7 hours to go until the RAID is rebuilt and again redundant.

Now I need to see why the 8TB usb drive I plugged in to it is not registering....


...a day later...

I still haven't gotten the 8TB usb drive to register properly on the Readynas...I plugged it into an Ubuntu system and used Gparted to take a look...there is a small windows partition at the front of the drive...probably for use as a live recovery drive or something...so I removed that partition and I am reformatting the entire drive...10% complete after most of a day.

So while waiting for that to go, I put my eSATA Raid as a network share and pointed the Readynas at it to do a backup...soon after the backup started it quit with a bunch of errors.

 (something along the lines of "cannot allocate memory" for each file failure)

...this was the solution for me...