1. OCAU Merchandise now available! Check out our 20th Anniversary Mugs, Classic Logo Shirts and much more! Discussion here.
    Dismiss Notice

Arduino beginner

Discussion in 'Electronics & Electrics' started by Agg, Jan 7, 2017.

  1. theSeekerr

    theSeekerr Member

    Joined:
    Jan 19, 2010
    Messages:
    3,336
    Location:
    Broadview SA
    You're on the right track, although the actual code you've posted is riddled with errors. Start here: https://www.arduino.cc/en/Reference/ServoWrite

    Code:
    #include <Servo.h>
    
    Servo ServoLft;
    Servo ServoRgt;
    
    void setup()
    {
      ServoLft.attach(9); // Left motor on  pin 9
      ServoRgt.attach(10); // Right motor on pin 10
    
      // Make the robot go forward at full speed
      ServoLft.Write(180); // An "angle" of 180 degrees will set a continuous servo to full speed
      ServoRgt.Write(180); 
    
      // Continue for 1 second
      delay(1000);
    
       // Make the robot stop
      ServoLft.Write(90); // An "angle" of 90 degrees will set a continuous servo to stop
      ServoRgt.Write(90); 
    
      // Wait for 1 second
      delay(1000);
    
      // Drive the left wheel forward and the right wheel in reverse to make a sharp right turn
      ServoLft.Write(180);
      ServoRgt.Write(0);
    
       // Continue for half a second
      delay(500);
    
       // Make the robot stop
      ServoLft.Write(90);
      ServoRgt.Write(90); 
       
    
    }
    
    void loop() {} 
    Note that with a continous servo you have no positional feedback, so there is no way to specify that the shaft should turn through a precise angle, and thus no way to make a 90 degree turn other than empirically determining how long the motors should be driven to do so.
     
  2. MUTMAN

    MUTMAN Member

    Joined:
    Jun 27, 2001
    Messages:
    7,655
    Location:
    4109
    Wont a stepper motor be a better option at that time ?
    or a regular DC motor and a H bridge driver ?
     
  3. Madengineer

    Madengineer Member

    Joined:
    May 27, 2011
    Messages:
    14,254
    Well I don't know? I've asked about it, but nobody has given me suggestions. It's my first real step into it. I've tried with stepper motors, and I mustn't have coded it right, or it was too much stress or something, but they're not working now (and I haven't been able to get them to work ever since).

    A servo motor isn't exactly the best. But I had it available.


    Do you think a regular DC motor and h bridge driver would be better? (I have no idea what a H bridge driver is but I'm googling it right now)


    Pretty sure I've got a H Bridge Driver at home (I bought a large kit of gear).

    Would this DC motor be usable?
    Wrong link

    https://www.ebay.com.au/itm/DC-12V-...hash=item4b1bb34b36:m:moCGDsFRaBJC_jtdjaGTUjQ
     
    Last edited: Nov 10, 2017
  4. theSeekerr

    theSeekerr Member

    Joined:
    Jan 19, 2010
    Messages:
    3,336
    Location:
    Broadview SA
    A servo motor is just a DC motor with an angle sensor, an error-proportional control circuit, and an H-bridge built in. A continuous-rotation servo is the same thing but with the angle sensor defeated such that it always reads 90 degrees - input angles less than 90 degrees will drive the motor one way, angles greater than 90 degrees will drive it the other way, with speed proportional to the difference from 90 degrees.

    So yeah. Same thing, just wrapped up in a somewhat handy package.

    But for wheeled robotics work a stepper motor (or some kind of encoder-feedback system) is much better, so you can dead-reckon approximate position and orientation from the rotation of the wheels and their circumference.
     
  5. Madengineer

    Madengineer Member

    Joined:
    May 27, 2011
    Messages:
    14,254

    So I should just use a stepper motor?
     
  6. theSeekerr

    theSeekerr Member

    Joined:
    Jan 19, 2010
    Messages:
    3,336
    Location:
    Broadview SA
    Depends what you're trying to build! If you don't actually need to know your position or orientation (for instance, a line-follower robot) it doesn't matter, and servos are a lot cheaper.
     
  7. Madengineer

    Madengineer Member

    Joined:
    May 27, 2011
    Messages:
    14,254
    Basically I'm automating a lego model (pneumatic excavator).
     
  8. theSeekerr

    theSeekerr Member

    Joined:
    Jan 19, 2010
    Messages:
    3,336
    Location:
    Broadview SA
    Automate in what sense? Are you motorising for remote control? Motorising a few parts for a mostly-static display? Building a fully autonomous vehicle to very slowly empty your sandpit? You can't pick an appropriate solution until you define your requirements.
     
  9. Madengineer

    Madengineer Member

    Joined:
    May 27, 2011
    Messages:
    14,254
    Basically I want to eventually setup motors to make it go forward and turn (when detected input from a knob of some sort) as well as other various motors to control functions of the excavator.
     
  10. oculi

    oculi Member

    Joined:
    Aug 18, 2004
    Messages:
    11,524
    why don't you just use lego motors then? H bridges are cheap as chips on ebay etc.
     
  11. MUTMAN

    MUTMAN Member

    Joined:
    Jun 27, 2001
    Messages:
    7,655
    Location:
    4109
    sounds like position feedback is required for at least some functions
    you need a mix of servo and dc motors on h bridges
    for the h bridge look for l298n on google

    edit its a l298n not a ln298
     
    Last edited: Nov 11, 2017
  12. desertstalker

    desertstalker Member

    Joined:
    Feb 5, 2005
    Messages:
    386
    Location:
    Melbourne
    Servos generally go to a certain position then stop, few of them are capable of 360deg rotation ( I have never used one). perhaps link to the device you are trying to control?
     
  13. Madengineer

    Madengineer Member

    Joined:
    May 27, 2011
    Messages:
    14,254

    Cause it's not as fun? :D
     
  14. PabloEscobar

    PabloEscobar Member

    Joined:
    Jan 28, 2008
    Messages:
    13,974
    Pretty sure the answer will be no, but is there any way of getting code back of an Arduino?... I put down my Xmas lights project a while back because I got distracted by something else shiny... It's Xmas now, and the boss wants lights... who am I to argue.

    However, I don't remember what was loaded onto the Arduino, or what pins to hook where, nor do I recall the last thing that was uploaded to it... so I'd like something like a 'show running-config' on a Cisco switch so I can see where I need to hook my inputs and outputs up to.
     
  15. pantner

    pantner Member

    Joined:
    Aug 31, 2004
    Messages:
    2,241
    Location:
    Perth, WA
    Not that i am aware of. The way i understand it, the code you input into the Arduino IDE is compiled before it is uploaded. Even if you could get it off you wouldn't be able to read it.
    I know it doesn't help now but, suggestion for future projectors, put the pin config into some serial prints at the start of the program defining the pins used, etc.
    What did the program actually do/how complicated was it? was it just a timing program that turned a FET/Relay on/off to make lights flash? or more complicated than that?
     
  16. PabloEscobar

    PabloEscobar Member

    Joined:
    Jan 28, 2008
    Messages:
    13,974
    Just spat out a bunch of stuff for the WS2812b LED's I'm using, using the FastLED library from memory.

    I just poked around with a jumper between the board and the LED strings, and found which pin I was outputting to, so it's all good. Now I can go back through all my old project files and find the one that seems to do the same thing :).
     
  17. desertstalker

    desertstalker Member

    Joined:
    Feb 5, 2005
    Messages:
    386
    Location:
    Melbourne
    Might want to put some sort of identifier (output to console or whatever they call the USB serial interface) on program start so you can tell what is programmed onto the arduino for next time.
     
  18. MUTMAN

    MUTMAN Member

    Joined:
    Jun 27, 2001
    Messages:
    7,655
    Location:
    4109
    Same idea ? Either way thats a handy tip for those of us that have only sporadic times with our toys
     
  19. PabloEscobar

    PabloEscobar Member

    Joined:
    Jan 28, 2008
    Messages:
    13,974
    So I'm still futzing around with my lights.

    FastLED is magical, and lets me run 4x100LED strings defined as an array, off 4 Digital Outputs on my Arduino.



    In Physical terms, there's a horizontal power cable strung along the top, tapped into for each vertical run of lights, also, for the signal wire, I've used some old Cat5 cable I had lying around, each string of lights is one pair, and I've tapped the sheath and fished out the required pair at each joint.

    I've done some continuity testing on each of the pairs and don't have any shorts, but something is not right.

    With no signal pin connected, a Strand of WS2812's shouldn't really be doing anything (I think it stays in whatever state it was at the end)... however, I can unplug 3 of the 4 signal wires from my Arduino, and still have all 4 strands displaying the demo.... I'm trying to work out where these phantom signals are coming from.

    Any ideas?
     
  20. MUTMAN

    MUTMAN Member

    Joined:
    Jun 27, 2001
    Messages:
    7,655
    Location:
    4109
    crosstalk on the ethernet cable ?
     

Share This Page

Advertisement: