Show Posts
Pages: 1 ... 327 328 [329] 330 331 ... 838
4921  Using Arduino / Programming Questions / Re: SoftwareSerial port not available? on: August 24, 2013, 08:24:49 am
It looks to me as if you are enabling each SoftwareSerial port immediately before you try to read from it. I don't think that will work. SoftwareSerial doesn't receive data at the point you call listen() or available() or read(). The port is enabled when you call listen(), and will receive and buffer any data that arrives from then on; the available() and read() methods let you find out whether it has got any data buffered, and retrieve it. If you call listen() for a different SoftwareSerial then this one will stop receiving.

I think what you need is a state machine which listens to the peripheral serial and waits until it recognises a command, then executes the command. A command that requires a response from a sensor would be executed by enabling the sensor's serial port (and hence disabling the peripheral's port), sending the command to it and waiting until response was received or a timeout occurred. Then the peripheral's serial port would be enabled (hence disabling the sensor's serial port) and you are back to the starting point.

It is inherent in this architecture that only one serial port is enabled at a time and while the sketch is waiting for a response from a sensor, it will ignore any subsequent input from the peripheral.

I haven't used it, but I understand there's an alternative SoftwareSerial library and I seem to remember that one of the improvements is that it allows multiple ports to be enabled simultaneously. If you believe you need this capability, I suggest you have look for that and see whether it does what you need.
4922  Using Arduino / Programming Questions / Re: Trying to write code for Blood pressure monitor , Please give reveiw on: August 24, 2013, 08:11:19 am
Before trying to write something complex, write something simple. Your code is riddled with syntax and logical errors and I suggest you put it aside for now and look at, understand and run the example sketches that come with the IDE before you come back to it and have another go.
4923  Using Arduino / Programming Questions / Re: Arduino to Arduino Serial Communication on: August 24, 2013, 08:07:03 am
CSV seems like a sensible encoding scheme to me, and using a newline to terminate each record seems like the most obvious approach when you are using a textual encoding scheme.
4924  Using Arduino / Project Guidance / Re: How divide a sketch on: August 24, 2013, 08:03:45 am
By your explanation this would be broken up into numerous somethings.

Yes, absolutely - and a quick skim through the code suggests that would not be hard to do and would IMO make the logic much clearer.
4925  Using Arduino / Project Guidance / Re: How to build a non-corrosive soil moisture sensor? on: August 24, 2013, 07:59:10 am
Can I put on some heat shrink for the top 5 inches you recon? What do you think?

That's exactly what I did.
4926  Using Arduino / Project Guidance / Re: How divide a sketch on: August 23, 2013, 06:32:19 pm
It's your sketch and whatever works for you at the end of the day, but even on the small programs suitable to be run on an Arduino it is IMO worth writing structured code and that would normally eliminate the need for very long functions. I'd prefer functions to be small enough to see the whole thing on the screen, and IMO if it's too long to be stored in a single file it's certainly too long to be a single function. If you're offended by the thought of a extra function call you can always declare them as inline functions, but I would have thought the overhead of a function call was irrelevant in all but the most performance-critical applications.
4927  Using Arduino / Project Guidance / Re: Using Serial port output data for C programming on: August 23, 2013, 06:27:10 pm
want to use the output for a C program on my PC, but for that I would have to keep something like a .txt file with the data I need (last 10 sonar sacans)

If I were you I'd design it so that there was a long-running process on the PC which read readings from the Arduino serial port and made them available to your 'C program'.

If you C program is long-running - or you don't mind having to wait for it to receive ten samples at startup - then the C program itself could do the whole thing. Otherwise, your long-running program will need to make the most recent ten rows available to the C program in some way. A shared text file isn't a brilliant way to pass the data because you have to deal with file locking issues but if you're comfortable with that level of technology then it could be made to work. Given a free choice I'd suggest dumping the data into a relational database and then chucking away the old data as it becomes obsolete - it's overkill in this case but gives you reliable shared storage independently of the two applications accessing it, and being able to keep them completely isolated eliminates a whole load of potential headaches.
4928  Using Arduino / Project Guidance / Re: How to build a non-corrosive soil moisture sensor? on: August 23, 2013, 06:21:10 pm
I use a pair of stainless steel cooking skewers driven into the soil about 10mm apart. My measuring technique leaves the two probes unpowered except when I'm actively taking a reading, and powers them briefly to take the reading, them powers them with the reverse polarity for the same duration - the goal of the reverse polarity wasn't to do with corrosion but to stop electrolysis from moving ions around in the soil which I thought might affect the accuracy long-term.
4929  Using Arduino / Programming Questions / Re: How can I invert the PWM signal? on: August 23, 2013, 11:23:34 am
As my previous experience, the PPM signal level will drop a half when the servo motor is running. So, I add a buffer,ULN2003A, between I/O pin and Servo motor. However, ULN2003A is a inverter. That is the reason that why I need to invert the PPM signal.

In that case I suggest you fix the underlying problem, rather than looking for obscure workarounds. If the external device is designed to receive a servo signal, it should not be drawing enough current to pull the I/O pin voltage down. What is it, and how much current is it drawing from the control input?
4930  Using Arduino / Programming Questions / Re: SoftwareSerial port not available? on: August 23, 2013, 11:15:46 am
Could you post a complete sketch that demonstrates the problem? Preferably with commented-out code removed, and the remainder formatted.

If the sketch contains a substantial amount of code not related to the problem then I suggest you create a simple test sketch containing the minimal code necessary to demonstrate the problem. Quite often the act of creating this will clarify the problem to the point that you can solve it for yourself, but in any case it reduces the amount of code we need to wade through.
4931  Using Arduino / Project Guidance / Re: How divide a sketch on: August 23, 2013, 11:10:54 am
You can also use Tabs within the IDE, the button for them is over on the right hand side.
For larger programs, I make a few:
main tab is the file name, I put some note there.
then a_presetup, all the # stuff, pin assigments, variable declarations
b_setup, this is void setup
c_void, the main sketch, maybe broken up also
d_more_void for example
e_functions
f_more_functions


This sounds alarmingly as if you are splitting function implementations across files, which is a very poor idea IMO. If a function is getting unwieldy, it should be refactored into multiple functions (which may be stored in the same file, or separate files).
4932  Using Arduino / Project Guidance / Re: Send TXT filles to arduino on: August 23, 2013, 11:07:56 am
Where do the changes come from? The more directly you access the current list the better - you don't really want a solution where you have to keep a copy of the list up to date.
4933  Using Arduino / Project Guidance / Re: Arduino Line following robot using PID on: August 23, 2013, 08:45:39 am
First of all I an bit of confused with my error value.. I mean how to drive the DC motors using this error value i got.

You don't. The error is an input to the PID. You use the PID control output to drive the motor. But it seems premature to worry about that unless/until you know whether your line detection is giving you accurate input data, and that you're capable of driving the motors correctly based on the PID output.
4934  Using Arduino / Project Guidance / Re: Controlling the speed and direction of a DC motor programatically on: August 23, 2013, 08:40:38 am
How would I go about doing this?

Understand what control algorithm you want to implement i.e. whether the motor speed is to be controlled by feedback from some sensor, simply by elapsed time, or some other criteria.

Set up the hardware to power and control the motor and write a simple sketch that carries out a simple sequence of motor actions to confirm you know how to control the motor.

Set up the hardware for any sensors you need and write a simple sketch that demonstrates you're capable of reading data from those sensors and get the results you expect.

Write the code which implements your chosen control algorithm to control the motor based on whatever inputs it needs.

Test, fix, repeat as necessary until it is good enough for your needs.
4935  Using Arduino / Project Guidance / Re: Serial Connection between 2 Arduinos on: August 23, 2013, 08:36:29 am
On the receiving side, use write() instead of println().

The problem is that you're receiving an ascii character code 48 (representing the character '0') but instead of writing the character code directly to the serial port (which would cause '0' to display in the serial monitor) you're printing the decimal number 48.
Pages: 1 ... 327 328 [329] 330 331 ... 838