Show Posts
Pages: 1 ... 3 4 [5] 6 7 ... 33
61  Using Arduino / Programming Questions / Re: SerialRead More than One Number on: October 12, 2011, 04:00:38 pm
Here is some working code then:
Code:
char startChar = '$'; // or '!', or whatever your start character is
char endChar = '\r';
char buffer[10];
boolean storeString = false; //This will be our flag to put the data in our buffer
int index;
int num;

void setup(){
  Serial.begin(9600);
}

void loop(){
  while(!Serial.available());  //This means the program will only send an output when you send an input. It prevents long lists of numbers coming out when you are not doing anything, but should be deleted in a normal program.
  while(Serial.available()>0){
    char incomingbyte = Serial.read();
    if(incomingbyte==startChar){
      index = 0;  //Initialize our index variable
      storeString = true;
      break;
    }
    if(storeString){
      if(incomingbyte==endChar){
        buffer[index] = 0; //null terminate the C string
        //Our data string is complete.  Parse it here
        storeString = false;
      }
      else{
        buffer[index++] = incomingbyte;
      }
    }
  }
  num=atoi(buffer);
  Serial.println(num);
}

The method is simple; type in $ followed directly by a number (E.G. $12345) then press enter. The arduino will print out the number you typed in. It works, but has one strange flaw... It types out each individual digit on a new line, then the whole number.
E.G.
0
4
45
459

Where have these extra numbers come from!?

Onions.
62  Using Arduino / Programming Questions / Re: SerialRead More than One Number on: October 12, 2011, 03:39:20 pm
Quote
This calls for delay() !
It most certainly does not. It calls for the sender to send some end-of-packet marker. If the sender sends 1234<cr>, the Arduino can read any available character, storing it in the array (followed by a NULL) if it is not a <cr>. If it is a <cr>, the the sketch should call atoi() with the array, use the value returned, and reset for the next batch of serial data.

Read the blog I first posted a link to.

My mistake. I thought you meant a call to serial read will stop the arduino from reading any data and accept any bits it has already received as the final number.
I assume for atoi() you pass it a char array, and the return value is the integer?
Code:
num = atoi(price[]);

Onions.
63  Using Arduino / Programming Questions / Re: SerialRead More than One Number on: October 12, 2011, 03:11:52 pm
Quote
If price were properly NULL terminated (and complete), atoi() could be used to convert the array to a value, without the issues involved using pow (it's smarter than that).
I knew of atoi(), but not how to use it. I decided to use pow() instead, although it is not something I have needed to use before...

Quote
Did you try it? Did you even compile it?
Nope  smiley-red

Quote
It isn't necessary to put a NULL in every position. Put a NULL in the first position, and then add a NULL after every character is added.
I've never thought of that, but it is a brilliant idea!

Quote
while, not While.
smiley-red

Quote
dataPiece is defined as a boolean, not initialized, and used as a number. byte is the same size, and implies that the variable being defined IS a number, while boolean does not.
I have absolutely no idea why I declared it as a boolean; as you say, declaring it as a byte would actually work (unlike boolean), without taking up any more RAM.

Quote
Serial data arrives slowly. This loop will read any data that has arrived. If half the number string has arrived, this code will read half a number, and assume it has the whole number.
This calls for delay() !

Onions.
64  Using Arduino / Programming Questions / Re: SerialRead More than One Number on: October 12, 2011, 11:40:58 am
Code:
char price[10];
int num;
int i;
//Variables

while(price[i]){
  price[i] = 0;
  i++;
}
i=0;
//Clear the array

While(Serail.available()){ //If there is stuff to be read,
  price[i]=Serial.read();
  i++;
}
//Save the data

num=0;
boolean multiplier;
boolean dataPiece;
while(price[i]){
  num+=(price[i]*pow(10,datapiece));
  i--;
  dataPiece++;
}
//Turn the array into an integer
This should work. It saves the numbers into an array as they come in, then turns them from an array to an integer.

Onions.
65  Using Arduino / Installation & Troubleshooting / Re: Arduino powers up but it's not in my device manager list on: October 11, 2011, 02:21:41 pm
I could not get my duemillanove to work when I bought it. I pushed the USB lead into the socket, the light came on, yet the computer refused to recognise it. Embarrasingly I found out, after several days, that I had not pushed the USB cable in properly. Although it felt secure, there must have been a bad/no connection for the serial lines. The solution? Push the USB cable in harder. I was worried about breaking it at first, and that could be a serious consideration. Until there is a connection, push. But before it breaks...

Onions.
66  Using Arduino / Project Guidance / Re: Standalone Atmel Atmega 8 on: October 09, 2011, 01:57:04 pm
Quote
Is it possible to program (and burn the bootloader) on an Atmega 8 with the Arduino Duemilanove (ATmega328p).
Yes!

Quote
Another question: What do I need to buy?
An arduino Uno? (Maybe)
No!

Quote
quartz? (Can I use the internal one?)
I'd use a quarts crystal, but it is possible to use the internal oscillator.

There are a number of pages about setting up a standalone board:
http://www.arduino.cc/en/Main/Standalone
http://arduino.cc/en/Tutorial/ArduinoISP
http://arduino.cc/en/Tutorial/ArduinoToBreadboard


Onions.
67  Using Arduino / Programming Questions / Re: Changing the threshold values via webpage on: October 06, 2011, 01:04:13 pm
The way I would start is by writing out the code for your HTML web page, then loading it onto a micro-sd card. There is a card slot on the new ethernet shields, which makes life easy. Next, you need to send this data out from the SD card to a web client. This is easy to do; just alter the web server example by adding in some code to read (and send) the data from the SD card. After that, you need to read what the website says when you click the submit button, then you can go about changing the variables.

Onions.
68  Using Arduino / Installation & Troubleshooting / Re: Did I fry my Arduino??? on: October 06, 2011, 11:53:43 am
Quote
It writes whatever I type in the serial monitor, but it does this even without the arduino jumpered?

It sounds to me like you fried the USB to TTL convertor. If you have another board you could try and upload a sketch with "Arduino as ISP". It should work if the ATmega is still alive. You will just have to remember not to use Serial.

Onions.
69  Using Arduino / Programming Questions / Re: Changing the threshold values via webpage on: October 06, 2011, 11:51:18 am
If you know HTML, you will know that it is possible to submit info from a webpage to a server with a simple form. The arduino can work as a server and present the HMTL page. You then need to process what the client asks for to decide if it is a request for HTML (http request) or some info. It is not too difficult, but still serves as an interesting project.
At the minute, I am doing something similar. I have the arduino serving up a login form. Then, you log in and can send emails through it! Or at least that is the idea... I can send an email or log in, but not do both. When a microcontrolller connects to the internet, things really get interesting!

Onions.
70  Using Arduino / Installation & Troubleshooting / Re: UNO schematic on: October 06, 2011, 11:41:41 am
http://arduino.cc/en/uploads/Main/arduino-uno-schematic.pdf

The SMD uno and through hole UNO should have exactly the same schematic, only a slightly different PCB design. More info can be found under "Uno" in the hardware section.

Onions.
71  Using Arduino / Project Guidance / Re: Read Encoder from USB Mouse on: October 05, 2011, 12:17:11 pm
It is possible to do this with a PS/2 mouse; search the playground for the PS/2 library. From what I have read though, USB speeds are too high for the arduino. Wether this is true or not, I don't know. It is likely that you will need special drivers for it though, which the arduino may or may not cope with. IMO, stick with PS/2 and stay happy.

Onions.
72  Using Arduino / Project Guidance / Re: Weather radar on: October 05, 2011, 12:14:35 pm
Quote
is it very complex building a weather radar?
Yes.

Radar works by sending out a pulse of microwaves. By working out how long it takes the waves to be reflected back, you can work out the distance away an object is.
Imagine an object is 1km away. The speed the waves will travel at is the speed of light, or 299 792.458 kilometres per second. That is 2*(1/299792.458) seconds before the reflected waves can be detected, or 6.6712819 × 10^-6 seconds. This will work out at approximately 0.00000667 seconds between sending out a microwave pulse and receiving it again. The arduino crystal pulses at 16MHz, or 16000000 times per second. That makes one pulse 6.25 × 10^-8 seconds in duration, or 0.0000000625 seconds. 0.00000667 / 0.0000000625 = 106.72, or 107 pulses between transmission and receiving it.
It is possible to measure this time with an 8 or 16-bit counter, both of which sit inside that IC that makes the arduino work. So theoretically, the software is possible. Now for the hardware...
The radars I have seen for small boats have either a 2 or 4 killowatt power consumption. That is one heck of a lot of power! Voltage*Current=power. Mains voltage (here) is 240V. 4000/250= a 16 amp current draw. These radars can detect objects ~24km away. 16 amps at 240 volts is easily enough to kill you. The microwave radiation could be harmful, but it depends on the wavelegnth, frequency and exposure, as well as whether you beleive the sceptics. Next, you need to process the data.
Although it can be done, it will not be easy. And that's assuming you can find a microwave transmitter and receiver...

Onions.

P.S. https://buy.garmin.com/shop/shop.do?pID=13490&ra=true 4kw radar, cost:£1799. All that money should say something about the complexity...
73  Community / Exhibition / Gallery / Re: Another Audio Spectrum Analyzer. on: October 02, 2011, 03:30:05 pm
That's pretty cool! You've tempted me to set one up myself some time... I know it is possible to use transistors with a resistor ladder to produce one bar of the EQ thingy (can't think of how to phrase it, so I'll draw the schematic). Do you have any codes? smiley-grin




There, badly drawn and missing LED series resistors, but it should work as an EQ thingy. smiley

Onions.
74  Using Arduino / Motors, Mechanics, and Power / Re: Rc car vs Arduino on: October 02, 2011, 01:32:29 pm
Onions, I need 2 H-Bridges because it's not good to power front motor(for steering) with so high current, if I use external power source for L293D.
The motor will only draw as much current as it needs, nothing more. As long as you provide it with the correct supply voltage, it will not blow. V/R=I. If the motor needs 5 volts, and has a 5 ohm coil, it will draw 1 amp of current. If it needs 5 volts and has a 10 ohm resistance, it will draw 0.5A (500mA). As long as you keep the voltage correct, the current will be fine.

Onions.
75  Using Arduino / Motors, Mechanics, and Power / Re: Rc car vs Arduino on: October 02, 2011, 01:11:09 pm
As far as I can see, the schematic looks good. Personally though, I'd use another motor driver IC for the second motor, rather than a transistor h-bridge. The IC appears to have room for 2 motors, so you can control both motors with just the one IC. This will remove the need for extra components.

Onions.
Pages: 1 ... 3 4 [5] 6 7 ... 33