The Shop > Electronics & IC Programing
Arduino programming, Mega 2560 ADK
Dawai:
Beginning tips, (wish I had this to start with)
TIPS IF you buy one, Load the "free" arduino IDE software, get it working, when you get your arduino in Hand, (plastic push pin it to a wood board so it don't short on something) connect it to your USB port, WINDOWS will see it as a new device, (do a "SPECIFY driver to install", go to the arduino directory on your machine (mine is in c:\program files\arduino\drivers), select drivers DIR there in the arduino directory, WINDOWS should see the proper driver and select it) once configured in windows, then go to your "control panel", SYSTEM, hardware, Device manager and look at your com ports, see in the com/LPT ports listing "new device" (mine was seen as a arduino on com port 4) and take note of the com port since yours maybe different, you can then set up-configure the arduino software with the proper com port, select the model arduino you have connected, and "UPLOAD" the example LED blink program..
IF YOUR Arduino blinks the onboard (pin 13??) LED.. you have just programmed your first code into it.. ANYTHING that can turn on a LED can turn on a TTL-AC module, or a SSR going to your 15 gallon beer boiler, or a Discharge SSR in a spark welder, spot welder, or???? You just have to make the logic-code do what you desire, cut and paste from other code projects freely available on the net.
NOTE, this model 2560 Mega ADK can source 40ma of power on a pin (according to their site).. THE TTL opto-22 PB4 racks-modules I use draw 12Ma, The SSR (solid state relays) I use on the beer cooker draw about 12-15ma. SO.. turning things on and off are no problem.
THE newest gecko drives, 203's have opto isolation that draw a tiny 3ma of current to turn on and off the step and directional signals.. you could connect directly to them without a breakout board, pc or micro controller.
<end beginning tips>
So. I bought myself a arduino.. it says right there on the website you have multiple ports.. after three days moving data around and getting garbage out of it.. it occurred to me, these lower level ports probably do not have much "buffer storage" and what it is doing is stripping the amount more than it can send out in a byte. Serial.write() function is a direct byte write, Serial.print() supposedly can send "strings", thou out the additional ports is garbage.. (how I figured that out? connecting a usb-232 to the secondary port and running a terminal written in vb)
I am getting crazy characters at the lcd, or.. same crazy items at the PC term program.. but the NORMAL USB port to the pc reads things a lil bit differently.. you print a "A", ascii 65 out.. it shows up on the pc arduino monitor as a A.. on the others as a underscore-space.. Had me scratching my head for a few days.
So. I have to go to a "bit by bit" and not "WORD" moves out the other 3 ports?? I guess that explains why there is very little information about RS232 equipped LCD's on Arduino site.. mostly they use a binary LCD, tied to several pins in half byte or full byte mode.. (parallel pin LCD) Bit logic will work great that way.. I'll find a old C serial port program on a bit by bit move and upload the code here later. I plan on using the extra com ports are "chinese scale readers" and to communicate with a remote serial control board..
Dawai:
CODE snippet, making PWM pin control a futaba servo follow a rotary encoder position, hacked together in about twenty minutes from examples online..
You can cut and paste it directly into your arduino program, just wire the devices like the description there in the comments at top..
What's it good for?? well a air throttle control on a wood boiler? or a smelter throttle?? steering on a rc?? or??
--- Quote ---/* 12-25-2013 (someone got a arduino for Christmas) THIS is a way to PWM the servo control line, apply 5 volts to the red and black lines on the RC servo
and use the yellow "signal" line as the control on a PWM pin, set a frequency out on the pin and it runs to
that position, the servo has a pot inside it that gives positional feedback.. when it reaches a equal to the
frequency in, it stops there, lower frequency and it tracks till pot-position is satisfied.
THE encoder is a clarostat two channel optical encoder with one phase waveform 90 degees out of synch
with the other phase, phase a, phase B.. by reading the current state, the past state, you can determine by
ginary tranfer the direction and amount of travel of the knob of the encoder..
Hacked together by COFER in Gawgia from examples provided with arduino software.. I do not take credit
THE encoder subroutine is not really reliable, but it serves a purpose to test instruments. THE other examples on the arduino site use interupts Those would be much better.
Components used, a futaba S3004 rc servo from previous project, a Clarostat 601-128-E66-140-8813 encoder
5vdc wall supply, common tied to 2560 ground & servo gnd, positive to the servo red, yellow to pin2 for pwm output, encoder pin1 5volts to positive, Pin3 common to ground, Pin2 is A phase to ard_pin28, Pin4 is Bphase to ard_pin30. This is a 5 volt ttl encoder.
*/
#include <Servo.h> // include the data file to operate the servo
Servo myservo; // create servo software driver object to control a servo
int val;
int encoder0PinA = 28; // to reflect the pins I used for encoder phase A
int encoder0PinB = 30; // to reflect the pin I used for encoder phase B
int encoder0Pos = 0; // to zero for positional on the encoder
int encoder0PinALast = LOW; // set the positon variable
int n = LOW;
void setup() {
myservo.attach(2); // servo on pin 2 to the servo object in my connections
pinMode (encoder0PinA,INPUT); // configure the pins as inputs
pinMode (encoder0PinB,INPUT); // set the pin as a input
Serial.begin (19200); // open the port to display the positon via terminal
}
void loop() {
myservo.attach(2); // servo on pin 2 to the servo object // servo pin
n = digitalRead(encoder0PinA);
if ((encoder0PinALast == LOW) && (n == HIGH)) {
if (digitalRead(encoder0PinB) == LOW) {
encoder0Pos--;
} else {
encoder0Pos++;
}
//***************************************************************
if (encoder0Pos > 180) encoder0Pos = 180; /// if more than 180,
if (encoder0Pos < 1) encoder0Pos = 1; // if less than 1, reset to 1
//**************************************************************
Serial.println(encoder0Pos); // print position to the term, w linefeed
Serial.println("/");
}
encoder0PinALast = n; // reset following flag
//*********************************************** servo function **************************
myservo.write(encoder0Pos); // servo position according to the scaled value
delay(5); // time delay waits for the servo to get there
}
--- End quote ---
AdeV:
I must admit, I'm a big fan of the Arduino - I never went for the Mega though, I have a Duemilanove, one of the newer ones (I forget its' name, haven't even used it yet) and a handful of Boarduino (Arduino clone on a miniature board, perfect for breadboarding).
So far... used mine to implement a digital combination lock (using keypad.h and servo.h); read various temperatures using either TMP36's or more recently K-type thermocouples using the MAX6675 decoder chip. I wrote most of a monitoring suite for a Lister CS - 3x TMP36s for coolant temp, 1x K-type for exhaust temp, an RPM sensor (hall effect). Even built it onto some stripboard & got it working.... all I need to do now is build the output side (so I'm not tied to a PC to view the data), and the start/stop controls....
The only thing I am not entirely sure how to do is load sensing - i.e. if I were to flick on the kettle, how can I sense this & begin the engine start sequence? Similarly, how do I detect no load to begin my shutdown sequence...?
Dawai:
Good Day to you, Happy NEW YEAR..
Turn on-off? you mean like a manual flip type switch? I use opto22 ttl-transistor modules for the things around here, 5 volts in turns on a transistor or TRIAC type relay inside for 5 amps.. inputs are as simple, you plug a input module into the rack and when it see's voltage on the line side it sends a ttl logic voltage to your board.. one side logic, other side field wiring..
Sensing a load, well more thought and more description needed.
Last night, while watching tele I did this..
Code snipped, I hope I commented it well enough to follow..
************************************************************
/*
Modified to read a IRPD sensor, has a center detector, and a left and right LED transmitter, turn on
both, read for center location, left, then right LED's to set road map ahead reflection.
BUILD a binary truth table to direct the bot. 0,0,0 or 1,1,1 or??
12-27-13, added the SERVO point subroutine to hunt when the sensor changes, like a steer mode.
*/
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
#include <Servo.h>
Servo myservo; // create servo object to control a servo, maximum of eight ;
const int led = 13;
const int lftled = 36; //'turn on the enable left;
const int rtled = 40; // 'turn on the enable right;
const int Sens = 32; //'this is the input from the sensor detect;
int Radar ;
int VARR;
int pos = 0; // variable to store the servo position
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
pinMode(lftled,OUTPUT);
pinMode(rtled,OUTPUT);
pinMode(Sens,INPUT);
Serial.begin(19200);
myservo.attach(2); // attaches the servo on pin 2 to the servo object
}
// the loop routine runs over and over again forever:
void loop() {
Radar=0;
digitalWrite(led,HIGH); // turn the LED on HIGH is the voltage level
digitalWrite(lftled,HIGH);
delay(5);
// look to the sensor valve only left.
VARR = digitalRead(Sens); // set the variable equal to the IRPD output
if (VARR = HIGH) {
// add left bit:
(Radar = Radar + 1);
}
{
// turn on the right LED and add right Radar.
digitalWrite(lftled,HIGH);
digitalWrite(rtled,HIGH);
delay(5);
// look to the sensor valve only left.
VARR = digitalRead(Sens);
}
if (VARR == HIGH) {
// add middle bit:
(Radar = Radar + 2);
digitalWrite(lftled,LOW);
digitalWrite(rtled,HIGH);
delay(5);
}
// look to the sensor valve only left.
VARR = digitalRead(Sens);
if (VARR == HIGH) {
// add right bit
(Radar = Radar + 4);
// turn LED off
digitalWrite(led,LOW);
digitalWrite(lftled,LOW);
digitalWrite(rtled,LOW);
delay(5);
}
{
Serial.println(Radar);
delay(10); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(10); // wait for a second
(Radar = Radar * 24); // in steps of 1 degree
myservo.write(Radar); // tell servo to go to position in variable 'pos'
delay(5); // waits 15ms for the servo to reach the position
}
}
Dawai:
I take it, reread that you have a home-generator system?? running off batteries and inverter till it "requires more" power?? like turning on a appliance?
That'd be a current sensing relay.. a "ct" or doughnut, pass load bearing conductors through it, it gives a 0-5 amp for the "coil rating" like a 200 amp CT will give 5 amps at 200 amps load.. but.. you do not have to just go through the coil once, To get the resolution up you would make more passes and loop your main load bearing cable through it more than once, it a 20 amp passed through 10 times would give 5 amps thinking it was seeing 200..
NOW how to convert that 1x?? transformer to a signal you can read?? I'd want some kind of opto buffer in that circuit to protect the arduino analog input.
OLD opto22- analog modules, they had a 0-5 amp input module, but required several voltages to work.. 5, -15, +15. Outputed some kind of frequency to the "B2" brain board they were normally tied to.. you could hack one of them with a scope and frequency generator..
http://www.ebay.com/itm/Opto-22-AD10T2-Relay-G1-100-Ohm-RTD-Isolated-Analog-Input-Module-/300931939960?pt=BI_Control_Systems_PLCs&hash=item4610f0fe78
I don't know what kind of signal they supply the B2 brain board?? coming in "software" logic to the monitoring PC is a FFFF or 4096 decimal number.. so.. I suggest it is a frequecy coming off the module. That module is a temperature, but they all send the same kind of ratio-voltage-frequency back to the brain, it never knows what it has in the rack, only ouputs a 0-4096 scaled representation of the input..
You might find a industrial type signal conditioner?? Like a relay with labeled outputs.. but those are normally out of a "normal modder's" price range.. in the thousands of dollars sometimes.
We are too cheap to do that?? You could also "monitor the throttle" and governor on the generator.. if it low-throttles - idles too much it is not needed..
(like a gas engine powered welder, how it works, current monitoring)
Look on the side of your inverter, they sometimes have a rs232, or usb port..
Navigation
[0] Message Index
[#] Next page
Go to full version