Show Posts
Pages: 1 ... 10 11 [12] 13 14 15
166  Using Arduino / Programming Questions / Re: Image on web on: July 09, 2012, 07:17:18 pm
you might try to use dropbox / from matlab save to your public dropbox folder / right click it there, to get the web url
use the web url in your arduino shield page /... (dont store it on your arduino)
167  Using Arduino / Programming Questions / Re: Please modify this code on: July 09, 2012, 07:05:48 pm
yes in this case its more handy to write it like that, less typing is better.

But suppose you wanted a more complex function to create a complex string for HTML formatting.
Based on the value of A the text color is red or green, and if A is below or above a treshold it should be bold too.
Things like that require longer peaces of code.

As i am not sure how good you are in coding, i just noted it could also be written as your function, with a name you like to add to it.
If your learning c++ from other languages, it might be confusing to see how functions are made.
Without words like "Function" , well c++ is a bit barebones syntax , compared to languages like python  or java or basic, or ...etc

Essentially   int() is a build in function for arduino its allready there.
168  Using Arduino / Programming Questions / Re: Please modify this code on: July 09, 2012, 01:59:31 pm
a small extra note
if you want a function to go from a string to number it goes like this

Code:
 
int ConvertStringToInt(string S)
 {
   return int(s);
 }


As mentioned earlier there is always one answer to a function so you could repeat it
If you have this function you can write

Code:
A = ConvertString(lux_v1);
B = ConvertString(lux_v2);

in this case its more typing work, but often functions are good to repeat complex computer math programming, so using functions is a good thing just to let you know  smiley-grin

169  Using Arduino / Programming Questions / Re: Please modify this code on: July 09, 2012, 01:45:29 pm
oh your realy new to code.. well ehmm you should dive into it why else you have an arduino?.
I dont have the ethernet shield so i cannt really rewrite and test your code.
Well maybe i still can help you, and give you guidance
As a general note type correctly
As i see in your code
Code:
int lux_v1 = readString.substring(7, 11);
int lux_v1 = readString.substring(12, 16);// lux_v2 = readString.substring(12, 16)
i added some marked command  // is for marking
in you code you give lux_v1 a value and the next line does the same to the same value
But most likely you wanted it to assign to lux_v2

Are those perhaps the values you would like to work with ?
Because there you took parts of string called readString
For strings, a string = "text like this"
The first character is counted as zero
So the command substring, takes from readstring the 0123456 7th  character till the 11th
However by nature if you take part of a string it will returned as a string to you.
There is a function to convert a number inside a string to an int
Code:
// put this in the setup part
int A = 0; 
int B = 0;
now you program knows of two variables A and B
You also had lux_v1 and lux_v2 who where not int's but strings
This how you get their text numbers into an int, place it in your main program below after where i spoted your typo.
Code:
A = int(lux_v1);
B = int(lux_v2);

Instead of A you might also name them like Lux_v1_AsNumber  perhaps more easy?

I also note that you use a function called    atoi()  as far as i know this is not part of the arduino language, i couldnt find a reference of it (there is no atoi here : http://arduino.cc/en/Reference/HomePage but perhaps its a function that was part of Spi or Ethernet includes ? well perhaps might be.

Oh nextyou have serial output... and web output.
So you should also upate your webpage with A and B i suppose ?
Take a look at your seccond usage of your  <body> statement ... that should be </body>
But just above that line you might write
Code:
client.println (<br>);  // in html web page language that is a new line
client.print ( "First value :");
client.print ( lux_v1 );  // yes we can keep the string, you might try int version too
client.print (<br>);
client.print ( "Second value :");
client.print ( lux_v2 );


I hope you will manage with this help, i cannt test your solutions.
What's always a good approach to programming is to divide your problems into smaller ones. Or slowly extend your program, with a lot of file saves in between. so your working code extends, until you reach a problem. so then you know its there. then try to solve it in small parts, look perhaps how other people solved similar c++ coding problems, hang around c++ forums, or place newbie questions at   "stack overflow"  >> google it.
You can also slowly extend the sample programs its a good way to learn how to code.
Books are nice too,  (but borring too) just try to code, thats where it all starts..
170  Using Arduino / Programming Questions / Re: why does it work this? on: July 09, 2012, 10:34:22 am
a stroke.. hmm your a bit like me constant headache..
maybe a mistake of syntax under c++,
i am aware of a few strange ways of typing in c++
but have not seen something like you typed.


int x=3;

x +=2; // is same as x=x+2;   results in 5

x *=2 ; // performs the operation x = x * 2 results in 6  if x still was 3

x++;  // x =  x + 1

doing a multiply in front of a variable that you would like to assign a value..
dont think its part of c++  ?
 
171  Using Arduino / Programming Questions / Re: Please modify this code on: July 09, 2012, 10:13:57 am
Code:
String s = "123,456";               // string
int i = s.indexOf(",");
int l = s.length();
int a = int(s.substring (0,i-1));  //result in a
int b = int(s.substring (i+1,l));  //result in b

ps check for typos, as i didnt  
Sorry lazy.. but maybe you where too ?
Or maybe not, your new to coding, well then i gave a sample.
172  Using Arduino / Programming Questions / Re: How to detect if the board is connected to PC? on: July 08, 2012, 07:56:55 pm
Perhaps try to think outside of the box.. dont detect it.
You might write to both usb and to the SD you do it in a circular logging way. (FILO)
Circular logging is sometimes used in databases to have some time window to be able to restore data
Ofcourse its not the best.. but its better then nothing, and it might be all you want.
That is if you do not have to much data (or else your SD will be full quickly)..but it will always overwrite oldest data (so there is a time limit of how much data can be recovered back in time)..
Also keep in mind how often you can rewrite your SD...
If it is important data get it to a networked file cluster or so ..

Not sure how SD storage works (i dont have it)
if you have a file system on it, then keep a pointer to oldest write somewhere, and update it once you overwrite your oldest stored data samples. (circular logging).
When connected to PC perhaps also store a date time on the SD
Perhaps use clock shield or so.

You might have 2 arduino's around, another one to replay a SD to your compter, to restore data
or write a program that replays trough a comlink to fool the original computer program

PS for medical data it might not be wise to use an arduino, see its license its not to be used in environments that could change the dead or alive situation of a carbon based life form..or something like that.
Ask yourself what is the cost if your solution would fail, its not foolproof hardware it will brakedown someday



PS It might interest you to read about atomic databases  (no its not about physics) >Exchange uses it.
173  Using Arduino / Project Guidance / voice counting 0 to 9 and some words without a shield. on: July 08, 2012, 06:57:22 pm
Well after all the blinking effects.
I wondered would it be possible to let a Arduino speak ?

I know the Duemilove has limited in memory for this, so i would first try only numbers 0 to 9 and some keywords.

Down sampling my wav i can get to a 92kb file.. still to much
Doubling the speed (should be played at 50% speed) gets it down half   46kb  (still to much)
Its a pcm mono unsigned 8000mhz 5.5 seconds fragment.
if i would only use the numbers its about 18kb .. but i like to use to extra key words.


One of the main problems to me
Is there a short routine to do frequency output ?
What would be i highest sound frequency ?
If i switch from frequency how fast can I switch (i suppose slower then the previous question) ?
 
>> thinking of letting a computer algorythm compress it to a simple ( frequency, duration )
>> and let a computer find some kind of best fit for it. (not sure yet how to)
>> it would be some kind of longterm project, just for fun to improve my programming skill

i've seen some sample from a guy who made a voicesynthesizer without a shield.
to be honestly i couldnt understand what was spoken, if sounds attempts surely result in something like that
then just advice me, that it is not do able.
174  Using Arduino / Programming Questions / Re: Let me share a c# sample string read from serial.println on: July 08, 2012, 02:19:58 pm
smiley

no, its not really flushing data, it was a way of speaking.
if you take a look at the code at this function :
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
       
you will find the difference of how each textbox gets its data.

---
End of packet marker, well i rather mind linebreaks, so i just reads whatever data is send and brings it back as the same string as was send by  serial.println its no problem if your strings are variable in size.
Also you wont need to install c# (but its a code demo) as a working executable is inside the zip too.
175  Using Arduino / Programming Questions / Let me share a c# sample string read from serial.println on: July 08, 2012, 09:33:57 am
Hello people here.

I improved upon a c# serial programming example, and i like to share it here.
This is a programming demo, and when started you will see options to connect.
Select your arduino comport, and select your baudrate, press start.

As for the demo, you will see two textboxes one on the left textbox1 and one on the right textbox2
When running the program will display the serial input from the arduino in both textboxes
The difference is, that the right textbox will only update on received whole line strings.
(serial.println)
It will not update on partial received data, if more then 1 line string is received it will also update per string.
In contrast the left textbox just flushes anything it receives including partial of strings.

Hmm fun but ehm why did i make it, you might wonder.
Well the point is, if you have a preformated string as output from your arduino.
And you would like to do something with it its much more easier, to work on the same string you tried to send. As compared to partial strings.

Imagine you would write in the arduino :
Serial.println("This is what i received.");
Serial.println("2678 do you like it?");

The left textbox1 might upate like :
---|This is wh|----|at i rec|----|eived. \r|----|\n 2|---|678 do y|---|ou like it? \r\n|  

However right textbox2 will update like :
---|This is what i received. \r\n|----|2678 do you like it ? \r\n|---

Practical..??
Well yes, if you know the syntax output from a GPS module or other data output it would be more easy to buildup on whole strings at a connected computer side, then parts of strings. I probably am not the first who solved it. But post it here so people who find this difficult to do com reading from c#, can use it.

Written in c# 2010 express  (free downloadable from Microsoft, just google it).


PS..
The code is as is, i'm not going to support it, or give long explanations about it, reason its working
But its a demo release and not a final version, as the final one wont include the leftbox, this version still does show the difference in programming, therefore you might learn from it. So instead of me explaining, i rather focus on a next version which will not be for a coding example, but will include some cool other stuff.



Just reply thanks if you liked it.
176  Using Arduino / Programming Questions / Re: Serial data read and write questions on: July 08, 2012, 08:17:48 am
Ok well here is my c# program, not yet translated it to arduino.
But the simple technique should be easily converted since commands are the same in c++ and c#
However capitalization differs, and some input/output formatting might differ. (linebreaks)
The whole simple trick is inside :
Code:
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)

Its simple
It got two text boxes, as for demo purposes the left textbox1 just flushes anything that is received.

The right textbox2 works different, it only updates whenever a whole string is received.
If more then one Arduino whole serial.println string is received, it will add them each separate as whole strings. If there is no full string yet received but a partial one, it will not update the textbox2.


To be able to handle full strings could be handy since often you know the string syntax that gets out and you like to work on that string again, so that should be easier to do on the right textbox2


I compiled it to use .net 4.0  but one could recompile to use 3.0 too i think.
I used c# express 2010 which is a free download from Microsoft.
the c# project is attached to this post,

Please let me know what you think of it.
177  Using Arduino / Programming Questions / Re: Serial data read and write questions on: July 07, 2012, 06:33:25 pm
just as a side note.

I guess a lot of serial communication problems arise from dealing with buffers.
Both connected PC and Arduino can suffer from that; 
Under c# a comport.readline functions is kindoff problematic .
Well as of this night i just wrote a function that outputs whole line strings as output.
Which is kind of nice since often the serial.println string originated as a fixed format.
And so you often now the position of numbers etc
And so it nice to those real strings in return as sended by the arduino.

I'm now about to port this c# function to a c++ function.
To get the same kind of buffer solution if there is fast communication in the other direction.
I doubt if the arduino wouldnt be able to keep up, however its more of a programming exercise to me.
(i have to train c# and c++ urgently for getting a job), it might be handy for other devices connected to the arduino.

Well i was thinking maybe it could simplify your code such function in c++.


PS  If it is possible to upload code here on the site i would gladly upload the c# code



178  Using Arduino / Programming Questions / Waht are the largest programs for arduino used for ? on: July 07, 2012, 11:17:29 am
I am wondering what are the largest programs people made running on a arduino to control something ?
I've read about a chess program, but not the actual size of it.
If your making something huge please respond, or if you did that in the past, and write the compiled size of your project.
Do some people's project get near the 4K limit of the arduino, i am curious.
179  Using Arduino / Programming Questions / Re: Serial data read and write questions on: July 06, 2012, 08:19:31 pm
I'm wondered too, what the code should do
apparently he's doing a char like character read of the serial communication.
puts these chars in an array , on which a patern search occurs    ","DA   
and then he...pwow.. this matching complexity continuous..

Ehm not sure why he does it like this, has he tried to do a serial readln ?  (readline or isnt the device returning linebreaks in the output ?)
There are also other commands like  http://arduino.cc/en/Serial/ReadBytesUntil   (till next readout start?)
Which basically puts data in an array till a certain character, all at once.
But then you have the data is working with chars inside an array handy. (duh dough any string is an array ehm hmmm.)

If you know the delimeter character (line break or something else)
You might as wel use a string, add chars to it, until you have a match
the String object has many handy function to build up on more advanced string match functions.

I guess not many people read out the data the way you do, and i'm not exactly sure if it has a benefit to do so.

There are also some code samples delivered with the arduino software download, take a look at serial examples too.
180  Using Arduino / Programming Questions / Re: servo moving very slow,only works for delay of 1500 or more on: July 06, 2012, 06:34:45 am
ehm you do use Mosfets ?

well, a mosfet has 3 pins, lets suppose a pin is connected to 12V (V in) and another pin to your arduino to control the mosfet (gate), and another (V out)to your motors magnet from where it goes to ground.

The principle of the Mosfet is that a charge in the gate creates a tunnel inside the Mosfet so the magnet inside your motor gets power.

Mosfet however require little charge to control that tunnel, this gate charge is tiny compared to the their (V out) power. If you overwhelm it with a lot of charge, then it takes more time before the charge is gone (and you might even destroy the Mosfet if you give it to much on the gate).

If it takes more time to discharge then it means it doesnt switch off as fast as you like.

So that would result that inside a motor more magnets might still be turned on.

Resulting in weak motor performance, for both speed and torsion


To resolve use resistors on the gate (its also protective for the Mosfet)




Pages: 1 ... 10 11 [12] 13 14 15