Showing posts with label command line. Show all posts
Showing posts with label command line. Show all posts

Monday, October 14, 2013

Sainsmart 8 Channel Relay

I recently purchased a Sainsmart 8 channel relay for use with some holiday lighting with my Arduino, I had some sketches already typed up for use with another project however I soon discovered that the relay board does not simply turn off with the normal LOW command with the digital output pins.I basically spent half a day writing up a new sketch and trying it until I got it to perform the way that I wanted it to. I have an ITEAD Mp3 shield I am using with it, so I cant guarantee this sketch will work for anyone else, But it’s a starting point since I found hardly any information on this relay board.This page is the best information I found but it only loops the relays so I had to us his example to formulate the code to do as I wished.If you look at your serial output and adjust the sense limit and smoothing you can get it to react to some some degree to the music.

IMG_0033[1]

 

// Sainsmart 8 channel relay v1.0
//



#define NUMREADINGS 70 // raise this number to increase data smoothing

int senseLimit = 400; // raise this number to decrease sensitivity (up to 1023 max)
int probePin = 3; // analog 3
int val = 0; // This is the reading from the probePin

#define RELAY_ON 1
#define RELAY_OFF 0

#define Relay_1 4 // Arduino Digital I/O pin number
#define Relay_2 5
#define Relay_3 6
#define Relay_4 7
#define Relay_5 8
#define Relay_6 9
#define Relay_7 10
#define Relay_8 11


// variables for smoothing

int readings[NUMREADINGS]; // the readings from the current analog input
int index = 0; // the index of the current reading
int total = 8; // the running total (Realys)
int average =0; // final average of the probe reading


void setup() {


pinMode(Relay_8, OUTPUT); // specify Relay Outputs
pinMode(Relay_7, OUTPUT);
pinMode(Relay_6, OUTPUT);
pinMode(Relay_5, OUTPUT);
pinMode(Relay_4, OUTPUT);
pinMode(Relay_3, OUTPUT);
pinMode(Relay_2, OUTPUT);
pinMode(Relay_1, OUTPUT);

Serial.begin(9600); // initiate serial connection for debugging/etc

for (int i = 0; i < NUMREADINGS; i++)
readings[i] = 0; // initialize all the readings to 0
}

void loop() {

val = analogRead(probePin); // take a reading from the probe

if(val >= 1){ // if the reading isn't zero, proceed

val = constrain(val, 1, senseLimit); // turn any reading higher than the senseLimit value into the senseLimit value
val = map(val, 1, senseLimit, 1, 1023); // remap the constrained value within a 1 to 1023 range

total -= readings[index]; // subtract the last reading
readings[index] = val; // read from the sensor
total += readings[index]; // add the reading to the total
index = (index + 1); // advance to the next index

if (index >= NUMREADINGS) // if we're at the end of the array...
index = 0; // ...wrap around to the beginning

average = total / NUMREADINGS; // calculate the average


if (average > 250){ // if the average is over 250 ...
digitalWrite(Relay_1, RELAY_ON); // Turn on the first Relay*
}
else{ // and if it's not ...
digitalWrite(Relay_1, RELAY_OFF); // turn that Relay off
}

if (average > 300){ // and so on ...
digitalWrite(Relay_2, RELAY_ON);
}
else{
digitalWrite(Relay_2, RELAY_OFF);
}

if (average > 350){
digitalWrite(Relay_3, RELAY_ON);
}
else{
digitalWrite(Relay_3, RELAY_OFF);
}

if (average > 375){
digitalWrite(Relay_4, RELAY_ON);
}
else{
digitalWrite(Relay_4, RELAY_OFF);
}

if (average > 400){
digitalWrite(Relay_5, RELAY_ON);
}
else{
digitalWrite(Relay_5, RELAY_OFF);
}

if (average > 450){
digitalWrite(Relay_6, RELAY_ON);
}
else{
digitalWrite(Relay_6, RELAY_OFF);
}

if (average > 550){
digitalWrite(Relay_7, RELAY_ON);
}
else{
digitalWrite(Relay_7, RELAY_OFF);
}

if (average > 600){
digitalWrite(Relay_8, RELAY_ON);
}
else{
digitalWrite(Relay_8, RELAY_OFF);
}


Serial.println(val); // use this output to aid in calibrating
}
}

Monday, July 18, 2011

Extended Terminal

For those who love using a terminal to do things as I do this is a "must have" I try to use the terminal for installs and updates just because I have been using Linux exclusively for about 10 years I think, and back in the days of Red Hat and such the terminal was your best friend. 

Byobu has a lot to offer and it shows you some good information.

Sunday, March 14, 2010

Slideshow Wallpaper

Here is a real simple XML script I changed around a little to fit my needs and I thought I would share, If you get sick of your wallpaper and would like it to change through out the day this script will do just that, it changes about every 30 minutes right now.I have only tried this with Gnome I am not sure how it will work with KDE it should be ok. If anyone tries this on KDE let me know. I have tried with Ubuntu and Mandriva also.



It will do 9 different wallpapers the way it is right now and you can add or remove as many as you want, all you must do is follow my example {/home/file#.jpg} you must be sure at the end you loop back to the first image in your show. what you need to do is create a folder where you plan to save them and put all the images there to begin with, then direct the script where to find them {/home/file.jpg} when you are done this save as an XML file in the same folder. now go to your desktop and right click and select background, then ADD and select the XML file.You can also go to System in the taskbar and preferences and appearance.

Tuesday, September 8, 2009

Brother Word Processor

Here is an old Brother word processor I came across and it even still works correctly. The printer even still has ink and functions. I remember back when I took some college classes (87-88) we had something similar to this we had to use.This isn't quite that old, this is circa 1992. I was surprised to see that i can still get ink for this reasonably cheap.




Friday, August 14, 2009

Terminal Screensaver


This is How to make a screen saver in UBUNTU that looks like a running terminal program the easy way.

First of all you want to make sure you have Xscreensaver-data and Xscreensaver-data-extra.

If not you can simply paste this code in a terminal. Or go to synaptic package manager.


----------------------------------------------------------

Sudo apt-get install xscreensaver-data


sudo apt-get install xscreensaver-data-extra

----------------------------------------------------------

Now you will want to go to the menu bar and select (system,preferences,screen saver) now select Phosphor if you go to advanced you will see you can choose a simple text file to use for your scrolling text to simulate a terminal program running. I just made my own with my text editor and saved it as a text file. Any type of text will work so you can pretty much customise it any way you wish.Good luck and enjoy.




Sunday, May 17, 2009

Ubuntu only Reports 1000 MHZ

I have an AMD Athlon X2 64 6000+ and it wasn't throttling up past 1000 MHZ so after reading a lot and some experimenting I found the solution.

This will tell you your current MHZ
cat /proc/cpuinfo | grep "cpu MHz" | head -n 1

This code will tell you all the possible MHZ frequencies your CPU supports


cpufreq-info
As it turned out cpu freq was not installed on mine so I had to install it.

sudo apt-get install cpufrequtils

Now when I use the CPUfreq-info command I get the correct stepping for my CPU.
You can also add CPU freq to your panel as an applet by right clicking on your panel and selecting it from the drop down list.

CPUs which need to switch frequency at the same time: 0 1
hardware limits: 1000 MHz - 3.10 GHz
available frequency steps: 3.10 GHz, 3.00 GHz, 2.80 GHz, 2.60 GHz, 2.40 GHz, 2.20 GHz, 2.00 GHz, 1.80 GHz, 1000 MHz
available cpufreq governors: conservative, ondemand, userspace, powersave, performance
current policy: frequency should be within 1000 MHz and 3.10 GHz.
The governor "ondemand" may decide which speed to use
within this range.
current CPU frequency is 2.40 GHz.
cpufreq stats: 3.10 GHz:2.25%, 3.00 GHz:0.64%, 2.80 GHz:0.32%, 2.60 GHz:0.42%, 2.40 GHz:0.40%, 2.20 GHz:0.32%, 2.00 GHz:0.32%, 1.80 GHz:0.42%, 1000 MHz:94.92% (33)

Wednesday, March 4, 2009

Enable JAVA In OPERA

I like a fast browser and it seems FireFox has been somewhat sluggish lately so I installed OPERA i was amazed that everything except java worked immediately.I have been using it for a few minutes and so far I like it I am going to give it a workout and see how well it holds up. as for getting java to work assuming you allready have the latest version installed on your computer, if you go to Tools/preferences/advanced/content on the toolbar of OPERA you can enable java and then you must point opera in the directory where your java is stored.


From linux if you have trouble finding java you can go to the terminal and put in
[find / -name libjava.so 2> /dev/null ] That will tell you the location to put in the opera window. now you can validate the java plugin to be sure it works. Thats it now you can enjoy a fast browser.

Tuesday, March 3, 2009

Using The Terminal

I know when i first started using linux about 8 or 9 years ago when I had a problem I would turn to forums and I would read a lot. I remember looking at all of peoples information neatly displayed however never knew how to get it myself for about the first year or so. there are several ways to get it but the fasted way I have found is with a Terminal and the DMESG command since you can do it without root permissions and such.


CPU0: Intel(R) Pentium(R) D CPU 3.00GHz stepping 07 Booting processor 1/1 ip 6000 Initializing CPU#1 Calibrating delay using timer specific routine.. 5999.15 BogoMIPS (lpj=2999575) CPU: Trace cache: 12K uops, L1 D cache: 16K CPU: L2 cache: 1024K CPU: Physical Processor ID: 0 CPU: Processor Core ID: 1 Intel machine check architecture supported. Intel machine check reporting enabled on CPU#1. CPU1: Intel P4/Xeon Extended MCE MSRs (24) available CPU1: Thermal monitoring enabled x86 PAT enabled: cpu 1, old 0x7040600070406, new 0x7010600070106 CPU1: Intel(R) Pentium(R) D CPU 3.00GHz stepping 07 checking TSC synchronization [CPU#0 -> CPU#1]: Measured 1095 cycles TSC warp between CPUs, turning off TSC clock.

this is an example of what you will get of course you will get a lot more information than this I just took out some of the information on my cpu for everyone to see.

Using the terminal scares a lot of people but you should get used to it and take advantage of it it is a very powerful tool that can actually save you a lot of time. when I use Ubuntu I almost never use the GUI for updates and do an [apt-get update] from the console. Just be careful and know what you are doing when using a Terminal in root because you can damage your system.