Show Posts
Pages: 1 [2] 3 4 ... 52
16  Using Arduino / Programming Questions / Re: Reading a packet of data in one call on: October 05, 2012, 12:05:37 pm
Output the BytesToRead and you're going to find that there aren't any to read, even with a proper connection.

Your processor operates many many times faster than serial communications, even through the overhead of the .NET runtime engine.  Not only are you not going to receive a result in the time it takes your code to get from the Write() operation to the Read() operation, but it's likely your command still hasn't even been sent by that point.

The recommended method of receiving serial data in C# is through the DataReceived event.  This is because you can't really predict when the data is going to arrive.
17  Using Arduino / Programming Questions / Re: Reading a packet of data in one call on: October 04, 2012, 09:47:46 am
There are a number of things your code is trying to do that just is NOT going to work.
You are trying to transmit multiple types of data between the two systems, and you have no reliable identification of the types of data that are being transmitted.  Not only that, but you want all these things to be handled in one call, which is still possible, but only magnifies the need to uniquely identify all the different types of data being transmitted.

For example:  You have a request for analog read data that immediately reads what comes back from the Arduino and assumes it's your result from that request.  Bad assumption.

In general, you have 4 different commands of varying lengths.  2 are expected results back also of varying lengths.  Your serial comms need to include a few things in order to make such a scenario reliable.

1.  Unique start and end of packet markers.  It is essential they be unique.  In other words, these start and end of packet markers cannot be used anywhere within the packet itself.
2.  Unique headers for each of the command types and response types.  The uniqueness is the same as for the start and end markers.
3.  A processing framework that either does not expect the result to be the very next packet of data received after the command is sent (flexible, but a bit more complicated to code), or strictly enforces a rigid command/response ordering for all commands (not as complicated to code, but introduces a lot of blocking and waiting, and isn't very efficient, responsive in general).

You are currently using binary serial comms, which makes a lot of the above more difficult (unique markers/headers in particular, since writing out an int value can generate any byte value output).  Switching to human readable transmission makes most of the above easier, but introduces a layer of conversion/parsing.  Both the Arduino Serial object and C# serial object provide provisions for converting, and both the Arduino and C# environment provide additional libraries for parsing.  As a result, it's generally easier to get human readable Serial comms functional than it is to get binary Serial comms functional.  It's also easier to debug human readable Serial comms since it's, well, human readable.
18  Using Arduino / Motors, Mechanics, and Power / Re: Communicating with Peter Norburg Stepper Board on: October 03, 2012, 05:30:23 pm
Quote
FYI. I tried taking out the delay here and the while loop just runs through. There needs to be a slight delay in order for the buffer to load in a character, it seems.
Serial.available() returns the number of characters currently in the buffer.  If it returns a value greater than zero, then there are that many characters in the buffer right then and there.  If removing the delay() caused your code not to work the way you want, then that's symptomatic of another problem.

Quote
You recommend dealing with collecting the incoming characters in an array rather than the string object?
Yes.

Quote
Like how I loaded all my command strings into the char* stepCommand[ ] array?
Sorta.  Working with C strings requires more effort than working with String objects, which is why most people are so fond of using Strings.  If you aren't very familiar with manipulating C strings, googling C string tutorial should provide plenty of guidance.  There are a lot of C library functions for handling all the heavy lifting, so it's not all that much more effort than using a String class.  It's just not all wrapped up in a nice package for you.

Quote
If I move the stepperboard IO to two other pins, will that send all Serial.println commands ONLY to the serial monitor and my Serial.write commands ONLY to my stepperboard? I'm trying to figure how I can print debug data to the serial monitor without freaking out the stepperboard.
If you use the software serial class to communicate with the stepperboard, you'll create a new serial object associated with those pins and use that object to communicate with the board, not Serial.  Something like...

Code:
SoftwareSerial StepperSerial(RXpin, TXpin);

//Send command to stepper board
StepperSerial.write(Command);

//Send message to Serial Monitor
Serial.println("Message out.");

There are plenty of examples out there using the SoftwareSerial library as well.
19  Using Arduino / Motors, Mechanics, and Power / Re: Communicating with Peter Norburg Stepper Board on: October 03, 2012, 12:05:28 pm
const int numCommands = (sizeof(stepCommand)/sizeof(char*));
This line of code gives me a value of 12, which seems to be right to me. Maybe even though I have 12 commands, this isn't the correct array size? I'm going to try your method, just trying to figure out why this doesn't work so I can understand what going on here.

Hmm, apparently I have misunderstood how sizeof() works in that situation.  If it's returning the correct array size, then ignore my comments, they're apparently incorrect.

On the String objects though, your commands are stored in C strings, which are just arrays of chars.  The String objects I'm referring to are
Code:
String readString;
String writeString;
Those are String objects.  The String class isn't working properly in the current version of Arduino and causes memory leaks over time.  Switch them to C strings as well.

As for your other questions...

1:  You cannot have multiple devices connected to the serial port at the same time.  If your stepper controller is connected to the serial port, then you can't connect to it with your PC (the usb port ties into that serial port.  The Uno only has the 1 hardware uart).  You could move the stepper controller to a softwareserial port on any of the other pins, allowing you to communicate with the Uno with the computer via USB while it's connected to the stepper controller.

2:  Serial.print(100) will send the string "100" out the serial port as 3 bytes of data corresponding the characters 1, 0, and 0.  It converts data to human readable ascii.  Serial.write(100) sends the numeric value of 100 out the serial port as a single byte of data.  When transmitting char data the output is the same either way.  In general though, if the intent is to transmit human readable text, use print/println.
20  Using Arduino / Motors, Mechanics, and Power / Re: Communicating with Peter Norburg Stepper Board on: October 03, 2012, 10:47:53 am
Your primary problem is with your calculation of the size of your Command array.

stepCommand is essentially a 2d array (and a jagged one at that).
This:
Code:
char* stepCommand[]
is the same as this:
Code:
char stepCommand[][]
Your calculation of the number of elements in this array is incorrect.  It's basically returning the total number of characters in the array, not the number of full command strings.  The way you're defining the array, there's no easy way to calculate the number of commands in the array.  Best to just handle that semi-manually, either with a #define or a const param.  I would include this value in the declaration of your array as well, like:
Code:
char* stepCommand[numCommands]
Doing so will cause a compile error if your param does not agree with your array (if you add another command to the array and forget to update numCommands value, it won't compile)

Beyond that, you'll likely run into problems with your String objects as well.  Best just not to use them.  They thrash memory pretty hard.
And while this probably isn't exhibiting itself as any sort of problem, there's no reason to have a delay between Serial.available() and Serial.read().
21  Using Arduino / Motors, Mechanics, and Power / Re: Forward/reverse motor control with stops - advice please on: October 03, 2012, 10:32:58 am
The only 'boards' you should need would be a motor controller board and the Arduino.

You explicitly call the drawer heavy, so you may need a motor controller with more oomph than the readily available shields for Arduino.  That all depends on the specs of the motors you plan on using.

Other than that, all the other hardware will be the same (drive rail, stop switches, power supply, etc.)
22  Using Arduino / Programming Questions / Re: Noob Programming Question on: October 03, 2012, 09:43:18 am
Grumpy Mike put together a decent guide to merging code:
http://www.thebox.myzen.co.uk/Tutorial/Merging_Code.html

It's not nearly as simple/trivial as web based scripts, but it can be done.
23  Using Arduino / Programming Questions / Re: A Better Fade? on: October 02, 2012, 03:04:41 pm
A logarithmic or exponential formula would probably provide a visibly smooth enough fade on/off.  It may not be a perfectly accurate method, but likely close enough that the human eye won't perceive any inconsistencies.
24  Community / Products and Services / Re: Highly Anticipated 32-bit "Due" due When? on: October 02, 2012, 09:36:21 am
Where is this so-called announcement on arduino.cc?  Yes, it was evidently 'announced' at Maker Faire, but until they actually get around to listing in their hardware pages as an official product (http://arduino.cc/en/Main/Hardware), or at least having an entry on the main page that gives the specifications and pictures, it is still vapour-ware IMHO.

Quoted for emphasis (although I don't personally consider it vapor-ware).

I only consider an announcement official if it's made to the general public through a direct company associated medium.  Maker Faire is neither a general public announcement or a direct company associated medium.

Otherwise, I give it marginally better credibility, at best, than rumor.
25  Community / Bar Sport / Re: WAY OFF TOPIC, but I would like some help getting my head around this. on: September 28, 2012, 09:16:13 am
As Graynomad mentioned, this is the biggest hurdle in converting requirements into code.  Requirements can be of varying levels of ambiguity.  There is zero ambiguity in code.

In this case, the phrase 'into the forest' needs to be more specifically defined.  Without that definition,  any answer is just an interpretation that may or may not be correct.  It could be half way, it could be all the way.  It could be something else entirely if 'into the forest' has some non-intuitive meaning.  For example, it could just as easily mean a single step if 'into the forest' is simply a binary state.
26  Community / Bar Sport / Re: The ARMs race on: September 28, 2012, 09:00:38 am
I havn't even got into v1 of the ide yet, I am waiting for someone to do a version of Gavin Smiths wonderful  " arduino cheat sheet" for the changes that are needed for v1.

I only spent a minute perusing that cheat sheet, but I didn't see anything that needed to be changed for v1.  At most there may be 1 or 2 very minor tweaks necessary to be 100% accurate.
27  Community / Bar Sport / Re: do you use android? on: September 28, 2012, 08:49:01 am
I used to have a cell phone, mp3 player, gps unit, and PDA.

Now, I have an Android.

Multitaskers >>>> Unitaskers.
28  Using Arduino / Motors, Mechanics, and Power / Re: Controlling 2x 24 volts DC, 450 watts motors. Where do i start ? on: September 28, 2012, 08:37:31 am
Quote
The maximum current on my motors are 4A, but that's only around stall, they typically run around 1-2A, so I have have a TIP120 and an L298 in series for each motor.

As retrolefty already said, it's never a good idea to operate electronics at or near their limits.  Doing so severely reduces the life expectancy and robustness of the circuit.  If it's a personal project, then it's a personal decision, so long as you understand the potential consequences down the road.  However, if you mix it with this...

No, i do not have lots of knowledge and experience but i'm ok with programming Arduino. I have to get 50+ units, would it be smart to go DIY and be guided ?

It's highly unlikely he needs 50+ units for his own personal use.  In those quantities, it's literally a necessity to use a robust, stable, and long lasting solution.  The consequences of not doing so are far more significant than when dealing with a one off setup.
29  Topics / Robotics / Re: Help with this code please. on: September 27, 2012, 01:29:02 pm
Code:
   myservo.write(180);             
   delay(15);
   myservo.write(90);             
   delay(15);
   myservo.write(0);           
   delay(15);

Most hobby servos read the signal line at a frequency around 50hz (about every 20 ms).  You're switching the direction at a rate faster than the servo is likely reading.  So, not only is the rate too fast for you to see what's happening, it's probably too fast even for the servo itself.

As wildbill recommended, try delays on the order of several seconds.
30  Using Arduino / Programming Questions / Re: Not passing array correctly to function on: September 25, 2012, 07:39:03 am
this...
Code:
struct Point
{
   double x;
   double y;
};

and this...
Code:
Point Collection [6][2] = {
    {1,9.3},
    {2,11.5},
    {3,12.25},
    {4,13.1},
    {5,14.2},
    {6,16.3}
};

What you're doing there is creating a two dimensional array of points, so 12 points total.  I can't be totally sure, but it doesn't look like that is your intent.  From your usage of Collection, it looks like you're really trying to just create a 1 dimensional array of 6 points and assign the x and y values using array initialization notation.

If the latter is what you're trying to accomplish, just drop the second dimension, use...
Code:
Point Collection [6] = {

Pages: 1 [2] 3 4 ... 52