Recent Posts

Pages: [1] 2 3 ... 10
1
Gonna cut straight to the cheese, im trying to use Serial Port to send commands to my servo, i have it all worked out, but i have to type numbers in.

int IT1 = 120;

Essentially thats what i have, but i have to type in the 120, is there a way to make it so i have to type in "IT1" into the serial port to execute the same command?

You dont have to read the code unless you want to......
Code: [Select]
#include<Servo.h>

Servo servo1;

const int IT1 = 120;
const int IT2 = 45;
const int IT3 = 0;

int Order = 15;

// Example 4 - Receive a number as text and convert it to an int

const byte numChars = 32;
char receivedChars[numChars];   // an array to store the received data
boolean newData = false;
int dataNumber = 1;  // new for this version

void setup() {
 
    Serial.begin(9600);
    Serial.println("<Arduino is ready>");
   
    servo1.attach(4);
   
}
void loop() {
    recvWithEndMarker();
    showNewNumber(); 
        if (dataNumber == IT1){
          servo1.write(IT1);
          delay(1000);
          servo1.write(180);
          delay(1000);
          servo1.write(90);
          delay(1000);   
          dataNumber++;
     } 
     if (dataNumber == IT2){
          servo1.write(IT2);
          delay(1000);
          servo1.write(180);
          delay(1000);
          servo1.write(90);
          delay(1000);   
          dataNumber++;
     }
     if (dataNumber == IT3){
          servo1.write(IT3);
          delay(1000);
          servo1.write(180);
          delay(1000);
          servo1.write(90);
          delay(1000);   
          dataNumber++;
     }
     if (dataNumber ==Order){
          servo1.write(IT1);
          delay(1000);
          servo1.write(180);
          delay(1000);
          servo1.write(90);
          delay(1000);
          servo1.write(IT2);
          delay(1000);
          servo1.write(180);
          delay(1000);
          servo1.write(90);
          delay(1000);
          servo1.write(IT3);
          delay(1000);
          servo1.write(180);
          delay(1000);
          servo1.write(90);
          delay(1000);   
          dataNumber++;
     }
}

void recvWithEndMarker() {
    static byte ndx = 0;
    char endMarker = '\n';
    char rc; 
     
    if (Serial.available() > 0) {
        rc = Serial.read();
       
        if (rc != endMarker) {
            receivedChars[ndx] = rc;
            ndx++;
           
            if (ndx >= numChars) {
                ndx = numChars - 1;
            }
        }
        else {
            receivedChars[ndx] = '\0'; // terminate the string
            ndx = 0;
            newData = true;
        }
    }
}
void showNewNumber() {
    if (newData == true) {
        dataNumber = 0;             // new for this version
        dataNumber = atoi(receivedChars);   // new for this version
        Serial.print("This just in ... ");
        Serial.println(receivedChars);
        Serial.print("Data as Number ... ");    // new for this version
        Serial.println(dataNumber);     // new for this version
        newData = false;
    }
}

2
Project Guidance / Re: Perboard Brownout but Work...
Last post by wvmarle - Today at 02:21 am
4 Ohm resistance that would suggest a peak current of 3A at 12V. That's a lot.

That photo also shows a solderless breadboard, not a soldered perfboard. Those breadboards may not be able to carry that much current.
3
Bar Sport / Re: Air conditioner petition f...
Last post by Qdeathstar - Today at 02:20 am
^sign me up
4
I dis-connected everything.
Took out another Nano (one that i had tested in the rig but hadn't made any difference).
Set the second Nano on the breadboard, along with another OLED.
Jumpered all the connections.
Fired it up. It works.
Breadboard version works, soldered version does not.

I had scrubbed that board with alcohol, and checked it for shorts. The only thing I can figure is that maybe there was a short somewhere else, that I hadn't found. Or maybe enough resin was still present to give squirrely results.

I have decided to make some PCB's that I can mount my Nano's on, that have solder pads a ways apart.

I want to thank each of you who tried to help me. But short of your seeing the soldered rig yourself, you couldn't have know it was a fabrication error somewhere.
5
Quote
Here's the code that I'm using right now.
I can't confirm your issue with a 50KHz square wave generated with this code inserted into setup() of your code. and pin 9 jumpered to pin 3

Code: [Select]
Timer1.initialize(20); //50KHz
  pinMode(9,OUTPUT);//timer output on 9, jumper to 3
  Timer1.pwm(9, 512);//50% duty cycle, square wave


I see counts of 201 with CHANGE and counts of 100/101 with either RISING or FALLING.

6
Project Guidance / Re: Perboard Brownout but Work...
Last post by TomGeorge - Today at 02:06 am
Hi,
I got a response but not enough info.
Tom,


Quote
The specs you will need are the following:
DC voltage
50 millisecond pulse
 6-9 volts
I have replied, saying it is for a battery application with a microcontroller and need to know current to see how to drive it.
Its the start of the  weekend so may need to wait for a reply.

Can you please post a picture of the valve/solenoid and its terminals?

Tom... :)
PS. What device that is designed for battery application does not have a power or current spec?????
PPS. I suspect the guy I'm talking to is a salesmen, not tech guy.
7
Français / Re: Comment récupérer une vale...
Last post by yoyol - Today at 02:01 am
up
8
Anyone?
9
General Electronics / Re: Simple flip flop or not?
Last post by aussiewill - Today at 01:56 am
Hi
Have now realised that I AM indeed in over my head and have decided that I'll just get the same servos that operate the points to operate micro switches to change the state of any or all LEDs.

So thanks again everyone for assistig.

Aussiewill
10
Not sure whether this is the right place to post this. I set up a very simple configuration using:

1 Pro Mini
1 Oled display
6 Peltiers
2 Thermometers
2 0,7A Fans
6 Relays
1 AC-DC adaptor 12V - 50A

The job is only about switching Peltiers on/of in order to keep a constant temperature over a metal plate.

PROBLEM: The sketch runs fine when the Pro Mini is connected to a computer and powered via USB. When I power it through the AC-DC adaptor, using a LM7805 to reduce 12 to 5V, the Pro Mini goes crazy. I tried 12V directly to raw and the pro mini not even blink.

What have I tried so far and did not work:

1- Putting the AC-DV far away from Pro Mini (field interference?)
2- Setting a 2nd AC-DC 5V totally separated from the 12 V, not sharing ground or whatsoever

Any clue about what could be the reason and solution to this problem?
Pages: [1] 2 3 ... 10