Show Posts
Pages: [1] 2 3
1  Using Arduino / Motors, Mechanics, and Power / Re: Newbie - HS-311 Servo 360 Continuous Rotation help on: March 28, 2014, 09:13:33 am
Code for testing and setup of servos. For my DIY continous rotation servos I send a 1500us position signal to the servo and tweek the pot until the motor stopps turning, then secure the pot in place. the below sail servo might be of interest, but is $$$.

http://www.robotshop.com/ca/hitec-hs785hb-servo-motor-2.html

Code:
// zoomkat 10-22-11 serial servo test
// type servo position 0 to 180 in serial monitor
// or for writeMicroseconds, use a value like 1500
// for IDE 0022 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h>
Servo myservo;  // create servo object to control a servo

void setup() {
  Serial.begin(9600);
  myservo.writeMicroseconds(1500); //set initial servo position if desired
  myservo.attach(7);  //the pin for the servo control
  Serial.println("servo-test-22-dual-input"); // so I can keep track of what is loaded
}

void loop() {
  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the string readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string
    int n = readString.toInt();  //convert readString into a number

    // auto select appropriate value, copied from someone elses code.
    if(n >= 500)
    {
      Serial.print("writing Microseconds: ");
      Serial.println(n);
      myservo.writeMicroseconds(n);
    }
    else
    {  
      Serial.print("writing Angle: ");
      Serial.println(n);
      myservo.write(n);
    }

    readString=""; //empty for next input
  }
}


This code works great! Just purchased a HS-311 from ServoCity and it had a POT. I had no idea what it did and now I see it simply sets the STOP point depending on the value inputted from the keyboard. Thanks for this.
2  Using Arduino / Programming Questions / Re: Decoding Serial TTL Pulses on: February 21, 2013, 01:41:47 am
Hi Nick,

I'm trying to verify the TTL message coming through MCP2551 (which is in pulsed form). I streamed the signal using a couple of the Communication and SerialtoASCII examples but all I was able to display was garbage. I'm just wondering if there is something more suitable for simply re-creating the message.
3  Using Arduino / Programming Questions / Decoding Serial TTL Pulses on: February 21, 2013, 12:43:42 am
Is it possible to decode serial pulse streams like http://www.picoscope.tv/general/serial-decoding-uart-rs232.html using Arduino?
4  Using Arduino / Networking, Protocols, and Devices / Arduino CAN BUS Shield Used to Listen on: February 20, 2013, 10:09:28 pm
I have a CAN BUS that is running at 125 KBPS. Also verified on an oscilloscope. I changed the bus speed  setting on the Arduinos CAN BUS Shield sample code ( sample code from http://www.seeedstudio.com/wiki/CAN-BUS_Shield) purchased from (https://www.sparkfun.com/products/10039) but it does not stream anything on the serial terminal.

The code I tried is attached (its set at 500 kbps by default).

I am using a Microchip MCP2515DM-BM as the BUS I am trying to connect to. They have an application called MCP2515 Bus Monitor which displays interpreted BUS data along with the register settings. I'm guessing the Arduino Library needs to set the MCP2515 on the shield to listen mode.


Thanks for any insight.
5  Using Arduino / Networking, Protocols, and Devices / CAN BUS Interface Question on: February 10, 2013, 01:27:11 pm
I have a module which I want my Arduino Uno to set its state. From reading some of the documentation for the module it is:

  • CAN BUS Reciever

  • Two Inputs
-Rx
-Tx
  • States - 4:
1- Initialize
2- Set to Ready
3- Set to Standby
4- Read Errors


From reading http://en.wikipedia.org/wiki/CAN_bus, it appears I need to know the "Protocol". I was wondering if someone could help me validate my methodology? Also, once I get the protocol, would it be a matter of setting a baud rate, start/stop bit etc???

Thanks for any insight.
6  Using Arduino / Installation & Troubleshooting / Re: AVRdude STK500 Timeout Communication Error on: February 05, 2013, 12:40:48 am
I solved my problem.

Solution: The wrong com port was selected in the Arduino IDE. I selected the correct port and my code uploaded just fine.

7  Using Arduino / Installation & Troubleshooting / [SOLVED] AVRdude STK500 Timeout Communication Error on: February 05, 2013, 12:33:38 am
Hello,
I have an Uno and it works great. The only real problem I have with it is my crappy programming, enough of my soap.

I changed the Programmer to Arduino MEGA 2560 (which is the only menu item that has a bit of a lagg when I click it):




I ordered a MEGA 2560 and for some reason Arduino 1.0.3 IDE gives the following errors when I try to upload code:

Quote
Binary sketch size: 5,886 bytes (of a 258,048 byte maximum)
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer

I have various vendors of micro controllers that I use on this workstation so I don't think its any issues with the USB ports or the OS (Windows 7 Pro).

Is there another bootloader or flash I that Arduino might have that may fix this?
8  Using Arduino / Programming Questions / Re: Sending Carriage Return [ENTER] to the Serial Port on: January 23, 2013, 08:02:00 pm
Code:
    Serial.write( 'o' ); // Turn  on 'o'
     delay(1000);
     Serial.write( '\r' );  // Carriage Return
     delay(1000);
     Serial.write( 'c' );  // Activate Continuous Function 'c'
     delay(1000);
     Serial.write( '\r' ); //  Carriage Return
     delay(1000);

Hmm, still hanging unless I press enter on the keyboard.

Code:
delay(1000);
     Serial.write( 'o' ); // Turn on 'o'
     delay(1000);
     Serial.write( '\r' );  // Carriage Return
     delay(1000);
     Serial.write( 'c' );  // Activate Continuous Function 'c'
     delay(1000);
     Serial.write( '\r' ); //  Carriage Return
     delay(1000);
9  Using Arduino / Programming Questions / Sending Carriage Return [ENTER] to the Serial Port on: January 23, 2013, 01:59:43 am
Hello,
I need to send a couple of characters to my device to get it going. I'm able to get the characters sent but I'm having trouble getting the 'carriage return' to be sent.

Referring to http://arduino.cc/en/Reference/ASCIIchart

Code:

     int poweron = 111;
     int cr = 13;
     int continuous = 99;
     Serial.write(poweron); // Turn  on 'o'
     delay(1000);
     Serial.write(cr);  // Carriage Return
     delay(1000);
     Serial.write(continuous);  // Activate Continuous Function 'c'
     delay(1000);
     Serial.write(cr); //  Carriage Return
     delay(1000);

If I press ENTER on my keyboard the two characters are sent to the serial terminal.

 smiley-roll-blue

Thanks for any help
10  Using Arduino / Programming Questions / Re: Convert String From Serial Data to Numerical Value on: January 22, 2013, 10:04:54 pm
If your system does not have a direct way of converting a number with a decimal point
from a character to a numerical representation,   you can always do it the hard way.

Read the digits before the decimal point (on the left of it),  as an integer.
Read the digits on the right of the decimal point,  and count them.
Create a float,  and divide the second number you read by ten several times
Add the first number you read.

Example:     read   1234.567 in characters
Get 1234 from this
Get 567 from this.  There are three digits
Convert 567 to a floating point number and divide by ten, three times.
You get .567
Now add 1234 to this.  You got  1234.567




I'm going to try this approach. None of the other functions mentioned in this post are working for me. I don't mind the practice.
11  Using Arduino / Programming Questions / Re: Convert String From Serial Data to Numerical Value on: January 17, 2013, 07:47:50 pm
Hi Arrrch,
I never meant to cause frustration or the obligation for a hand out. I chose Arduino because of the vast amount of sample code I can read and practice with along with the awesome support by so many vendors (including this forum). Yes, my philosophy to learn is to try (actual hands on); and keep trying until it works. I exhaust all literature that I can understand. I avoid inconveniencing those around me until I am too "lost in the woods". Right now I feel like I'm in the Amazon by some ancient undiscovered Mayan village.

That being said, thank you for the example. I will use it as a study example along with the rest of the recommendations on this thread to try to understand this functionality as much as possible.
12  Using Arduino / Programming Questions / Re: Convert String From Serial Data to Numerical Value on: January 17, 2013, 06:33:33 pm
Hi Arrrch,

I took a look at the references you mention explaining strings but it still does not explain how to read strings coming in from the serial port.

On a good note, I was able to isolate the variables of interest (after the second comma)

Quote
135.846,4.712,282.736


Quote
4.71

For now I am willing to settle to convert the second string in to a integer. The problem I ran in to is I'm unable to save the string of digits in to an array for later use.

Code:

if (sensor_stringcomplete)                                                  //if a string from the Atlas Scientific product has been received in its entirety
{
    Serial.println(sensorstring);                                             //use the hardware serial port to send that data to the PC

    for (int i=6; i<11; i++)
    {
        Serial.print(sensorstring[i]);
        int f = sensorstring[i].toInt();
    }

    Serial.println(" this is the string of interest");

    sensorstring = "";                                                      //clear the string buffer:
    sensor_stringcomplete = false;                                          //reset the flag used to tell if we have received a completed string from the Atlas Scientific product
}


Unfortunately
Code:
int f = sensorstring[i].toInt();
does not work. I would also assume it would be out of the scope to use this value outside the brackets.

If I simply use
Code:
int f = sensorstring.toInt();
it compiles but that is only the first string before the first comma.
13  Using Arduino / Programming Questions / Re: Convert String From Serial Data to Numerical Value on: January 17, 2013, 02:11:24 pm
Easy, readString.toFloat();

Not included with Arduino's version of the String object library, much like sprintf() doesn't accept the %f format specifier.

Hi Arrrch,
Does this mean its not possible to convert a string to float in Arduino?
14  Using Arduino / Programming Questions / Re: Convert String From Serial Data to Numerical Value on: January 17, 2013, 02:06:26 pm
Easy, readString.toFloat();

Check this out,
http://mootools.net/docs/core/Types/Number

Uhm, not sure what I'm doing wrong.

Code:
int n = readString.toFloat();

Quote
error: 'class String' has no member named 'toFloat'
15  Using Arduino / Programming Questions / Re: Convert String From Serial Data to Numerical Value on: January 17, 2013, 01:55:22 pm
What is the syntax to convert to floating?

Code:
int n = readString.toInt();
Pages: [1] 2 3