Friday, December 30, 2016

Legacy computer home automation server


Using legacy systems to do home automation when an Arduino or Raspberry Pi may not be available. They can work just as well. 


Server is a Pentium III with Ubuntu and Apache2. Enabled CGI (common gateway interface). Wrote all my own scripts using html, bash, and compiled freebasic (controls the leds).    Leds are connected to the parallel port via a home made adapter cable. Most of the code and interfaces are described in previous articles.  Added the video to the home web page:


Time to control real world object such as a coffeemaker.


For more information: http://www.tldp.org/HOWTO/text/Coffee

Wednesday, December 28, 2016

Chromecast ethernet.


You can use ethernet with the Chromecast (1), you just need a usb ethernet adapter and then a otg y host adapter (system must be up to date).


Then it should be plug and play if you have the right ethernet adapter. Tried my ethernet adapter and it did not work. Went to Frys who had the right usb to ethernet adapter.



All was well till I found that the Home android app on the Nexus 7 did not seem to support ethernet. Though I did not spend anytime seeing whether it could be done. A bummer.

Monday, December 26, 2016

Five volt adapter.

If you have a bunch of old +5v powerblocks with barrel connectors, then you may think they are worthless. Not so you can now get adapters to keep using the old powerblocks with your Raspberry Pi.
With the adapter, you can still use the power block as you always have and no soldering required.

You could also adapt an old computer power supply. Dangerous!! Wrongly set up it could KILL you Do not do this without expert help. Every power supply is different so you will have to tget the pinout for your power supply to be used. Do not do anything while the splly is plugged in on or off!!!!  Suggestions: User your favorite search engine.
AT:

ATX:


Polarity matters:




Barebone arduino ethernet.

Notice: use at your own risk.


If you have an Arduino with a removable chip, then you can use that to program the chip. Otherwise there are circuits to program the standalone Arduino. See "https://www.arduino.cc/en/Tutorial/ArduinoToBreadboard" for more details".

 


The bare Arduino setup.


You need a power source not shone. We used a 4 D size battery setup. Barebones setup before adding ethernet:



Wiring:







 Downloaded the latest Arduino and Ethercard software. Loaded both of them on the computer. Imported code for a simple web server.

// Present a "Will be back soon web page", as stand-in webserver.
// 2011-01-30 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php

#include <EtherCard.h>

#define STATIC 0  // set to 1 to disable DHCP (adjust myip/gwip values below)

#if STATIC
// ethernet interface ip address
static byte myip[] = { 192,168,1,200 };
// gateway ip address
static byte gwip[] = { 192,168,1,1 };
#endif

// ethernet mac address - must be unique on your network
static byte mymac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x28 };

byte Ethernet::buffer[500]; // tcp/ip send and receive buffer

const char page[] PROGMEM =
"HTTP/1.0 503 Service Unavailable\r\n"
"Content-Type: text/html\r\n"
"Retry-After: 600\r\n"
"\r\n"
"<html>"
  "<head><title>"
    "Service Temporarily Unavailable"
  "</title></head>"
  "<body>"
    "<h3>This service is currently unavailable</h3>"
    "<p><em>"
      "The main server is currently off-line.<br />"
      "Please try again later."
    "</em></p>"
  "</body>"
"</html>"
;

void setup(){
  Serial.begin(9600);
  Serial.println("\n[backSoon]\n");
   
  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
    Serial.println( "Failed to access Ethernet controller");
#if STATIC
  ether.staticSetup(myip, gwip);
#else
  if (!ether.dhcpSetup())
    Serial.println("DHCP failed");
#endif

  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip); 
  ether.printIp("DNS: ", ether.dnsip); 
}

void loop(){
  // wait for an incoming TCP packet, but ignore its contents
  if (ether.packetLoop(ether.packetReceive())) {
    memcpy_P(ether.tcpOffset(), page, sizeof page);
    ether.httpServerReply(sizeof page - 1);
  }
}

Finished setup:



Thursday, December 15, 2016

Documentation is bad sometimes.




Sometimes you just want to tear your hair out when the documentation of a product is WRONG. Something I ran into recently when trying to attach an enc28j60 from Hanrun to my genuine Arduino. I have used the ethernet shield on the Arduino without a hitch. So I supposed there would be no problem again... So I thought. Followed the map for hooking the two devices together as follows:

VCC -   3.3V
GND -    GND
SCK - Pin 13
SO  - Pin 12
SI  - Pin 11
CS  - Pin  8

Downloaded the latest Arduino and Ethercard software. Loaded both of them on the computer. Imported code for a simple web server.

// Present a "Will be back soon web page", as stand-in webserver.
// 2011-01-30 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php

#include <EtherCard.h>

#define STATIC 0  // set to 1 to disable DHCP (adjust myip/gwip values below)

#if STATIC
// ethernet interface ip address
static byte myip[] = { 192,168,1,200 };
// gateway ip address
static byte gwip[] = { 192,168,1,1 };
#endif

// ethernet mac address - must be unique on your network
static byte mymac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x28 };

byte Ethernet::buffer[500]; // tcp/ip send and receive buffer

const char page[] PROGMEM =
"HTTP/1.0 503 Service Unavailable\r\n"
"Content-Type: text/html\r\n"
"Retry-After: 600\r\n"
"\r\n"
"<html>"
  "<head><title>"
    "Service Temporarily Unavailable"
  "</title></head>"
  "<body>"
    "<h3>This service is currently unavailable</h3>"
    "<p><em>"
      "The main server is currently off-line.<br />"
      "Please try again later."
    "</em></p>"
  "</body>"
"</html>"
;

void setup(){
  Serial.begin(9600);
  Serial.println("\n[backSoon]\n");
   
  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
    Serial.println( "Failed to access Ethernet controller");
#if STATIC
  ether.staticSetup(myip, gwip);
#else
  if (!ether.dhcpSetup())
    Serial.println("DHCP failed");
#endif

  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip); 
  ether.printIp("DNS: ", ether.dnsip); 
}

void loop(){
  // wait for an incoming TCP packet, but ignore its contents
  if (ether.packetLoop(ether.packetReceive())) {
    memcpy_P(ether.tcpOffset(), page, sizeof page);
    ether.httpServerReply(sizeof page - 1);
  }
}



Then I proceeded to compile it.  Actually I had used other bits of code that would not compile until used this code. Well I proceeded to compile the code using a static ip address and all was well or so i thought. Brought up a web page and obviously it did not work. So like any good tech, you go to the web to get an answer, There were suggestion to change the mac address, and even using the +5 volt line instead of the 3.3v line. All of which did not work. Eventually I found an article that said the ethernet shield module used the #10 line on the Arduino.  The current configuration used the #8 line. What??? With nothing to lose, I used the #10 line instead of the #8 and viola everything worked with the 3.3v line being used. Whew that was a killer, Bad documentation will eat your lunch. Surprised I did not see that fix on the web, The new configuration is now:

Arduino         Module
digital 12         SO
digital 11         ST
digital 13         SCK
digital 10         CS
3.5v                  Vcc
Gnd         GND



So here are the results!



It seems to work with the Arduino mega also.

Monday, December 12, 2016

PiFM sorta

Wanted to be able to send music to speakers outside the house say for a barbecue or whatever. Could use Blue tooth among other things, but I wanted something more secure and easier to generally implement. PiFM seemed to be an answer . With a RPi you can send an old fashion radio signal to a radio and the radio will play what is sent it. All you need is an up to date Raspian install on a Raspberry Pi with internet access. I used the original  Raspberry pi for this project. I will probably set one up with the RPi zero. (Note: check you local laws to see if this is allowed.) Also you need to have experience using you RPi remotely.

Antenna needs to be at least 7-14 inches long.


You need to log into your Rpi command line. All this can be done easily. First thing is to get some software from the software repo for doing software development. Don't worry it will not hurt too bad.

Update the system:

$ sudo apt-get update
$ sudo apt-get upgrade -y
$ sudo apt-get dist-update -y

Get the files you may need:

$ sudo apt-get install zip make gcc g++ mpg123
$ wget https://github.com/markondej/fm_transmitter/archive/master.zip
$ unzip master.zip
$ cd   fm_transmitter-master

Now let's compile the project.

$ make


Get a FM radio and tune it to the frequency you have chosen

$ sudo ./fm_transmitter [-f frequency] [-r] filename

You should hear the file play on the radio. I used a transistor radio to see where the signal  transmitted to. You can get into some fancy batch files so you can manage your music, but that is for a later time,

Untested :

    Download a few of your favorite mp3 files to the Pi, or you can scp them. Make sure to put them in the /home/pi/Music directory.
    From the command line, type in the following command. The number 88.3 is the frequency the Pi will broadcast at. sudo /usr/bin/mpg123 -4 -s -Z /home/pi/Music/* | sudo /home/pi/pifm/pifm - 88.3
    Note: If you want to stash your mp3 files in a different directory, simply change the directory path that's underlined in the command above.
    Caution: Commands and filenames are case sensitive in Linux, so make sure you duplicate the exact capitalization of the previous commands.

Saturday, December 10, 2016

Arduino conversion.

Using the Arduino development boards can be cumbersome and a bit more expensive. But for simple projects, a standalone Arduino chip just just the right choice. We will convert a typical circuit for a board to a standalone chip setup.



int piezoPin = 8; // Declaring Piezo Buzzer on Pin 8
int ldrPin = 0; // Declaring LDR on Analog Pin 0
int ldrValue = 0; // Reading different values from the LDR
void setup()
{ 
}
void loop() 
{ // Starting the cycle functions below
   ldrValue = analogRead(ldrPin); // read the value from the LDR
   tone(piezoPin,1000); // Play a 1000Hz tone from the piezo (beep)
   delay(25); // wait a bit, change the delay for fast response.
   noTone(piezoPin); // stop the tone after 25 ms in this case 
   delay(ldrValue); // wait the amount of milliseconds in ldrValue
} // End of cycle functions 
 
 


Or

 


// variable declaration
// sensor value
int value;
// low sensor value calibration
int low;
// high sensor value calibration
int high;
// digital ouput pin where the buzzer is connected to
int buzpin = 8;
// LED pin alert calibration
int led = 13;

void setup() {
pinMode (buzpin, OUTPUT);
pinMode (led, OUTPUT);
// turn LED on
digitalWrite(led, HIGH);
// calibration for the first 3 seconds after program runs
while (millis() < 3000) {
// record the maximum sensor value
value = analogRead(A0);
if (value > high) {
high = value;
}
// record the minimum sensor value
if (value < low) {
low = value;
}
}
// turn LED off
digitalWrite (led, LOW);
}

void loop() {
//read the input from A0 and store it in a variable
value = analogRead(A0);
// map the sensor values to a frequency range 50 Hz - 4000 Hz
int pitch = map(value, low, high, 50, 4000);
// play the tone for 20 ms on buzzer pin 8
tone(8, pitch, 20);
// wait for a moment
delay(10);
}