Show Posts
Pages: 1 ... 3 4 [5] 6 7 ... 18
61  Using Arduino / Programming Questions / Re: Convert int to char and append to buffer on: June 16, 2012, 09:37:21 am
strcpy(buffer+strlen(buffer), " ");

Edit: fixed param order
62  Using Arduino / Programming Questions / Re: Pointer explanation on: June 15, 2012, 01:16:09 pm
char test = "A";

I would be surprised it the code above doesn't raise a compiler error or warning.
63  Using Arduino / Programming Questions / Re: Pointer explanation on: June 15, 2012, 01:12:17 pm
char test = "A";

This is not probably what you think. If you want that variable test holds a single character, use single quotes like this:

char test = 'A';

Or if you meant to declare a character array, add [] after the variable name:

char test[] = "A";

64  Using Arduino / Programming Questions / Re: Which bit changed? on: June 15, 2012, 08:44:30 am
You probably mean something like this:

 unsigned char port = 0b10; //
  int pos = 0;
  int i=0;
  for (i=0; i<8; i++) {
    if ((port >> i)&0x1) {
      pos = i+1;
 // pos == 2 here
65  Using Arduino / Programming Questions / Re: "Filtering" Char Array on: June 11, 2012, 04:40:24 am
How do I get the next 3 characters after "L" and set them to a new array?

You can use memcpy:


for(int x =0; x < packetSize +1; x ++){
   if(packetBuffer[x] == 'L') {
     //get the next 3 characters and set them to Lspeed[4] char array
    char Lspeed[4];
    void *pos = (void *) &(packetBuffer[++x]); // address of the next char after 'L'
    memcpy((void *)Lspeed, pos, 3); // copy three chars
    Lspeed[3] = 0; // terminate the string
    x += 3;  // update the index
   Lmotor = atoi(Lspeed); //convert to Lspeed array to integer for use in motor speed set command
66  Using Arduino / Programming Questions / Re: Parsing strings on: June 10, 2012, 08:02:47 am
"%hhd"  seems to work for uint8_t.
The bizarre  behavior was probably result of overflow in sscanf  (using 8bit variables where 16 bit variables where expected).
67  Using Arduino / Programming Questions / Re: Parsing strings on: June 10, 2012, 06:03:58 am
I'll guess that the format string does not match the data type. "%d" probably expects a 16 bit integer and uint8_t is 8 bits. I'm not sure what is the correct format string in the Arduino for uint8_t. Try to change uint8_t to short or int.  It should work as well, although it consumes a few bytes more ram.
68  Using Arduino / Programming Questions / Re: Parsing strings on: June 10, 2012, 04:17:13 am
The problem is that you use a wrong data type for minute, hour etc.  When you parse the string "15,X...", minute will have a binary value of 15  (hex 0xf) which is some non-printable ascii character.
use uint8_t instead of char. (Int or short should also work).

uint8_t minute, hour, day, month, dayOfWeek, pin, on, duration;

Use some special short value (e.g., 255) for 'any' instead of 'X'.  If you fix the data types you should be able to use also the simpler sscanf variant .

(Edit: short => uint8_t)
69  Using Arduino / Programming Questions / Re: Odd need to convert unsigned long to a byte array on: June 08, 2012, 06:00:21 am
Why do you need to convert an integer to a byte array for Serial.write? If you want to send an integer from the Arduino to a PC in binary form, you can use the method Coding Badly suggested.  However, you will probably have to take into account the endianess in both system. Normally if you send integers between different machines/OSs, you convert them into and from the network byte order using hton{l,s} and ntoh{l,s} functions, i,e.:

// In the sending end
outputLong = htonl(outputLong);

// In the receiving end
inputLong = ntohl(inputLong)

70  Using Arduino / General Electronics / Re: Measuring Current in Sleep and Active Mode on: June 05, 2012, 01:34:19 pm
I find wrapping the fuse in tinfoil works well.

Is it you, MacGyver?
71  Using Arduino / Programming Questions / Re: Any experience with run levels in linux and daemons? on: June 01, 2012, 01:40:23 pm
I don't think that running "/etc/init.d/zoneswitch start" will show you any more error messages than "service zoneswitch start" because Proc::Daemon::Init in the perl script detaches stdout/stderr from the terminal. You could of course try to comment out Proc::Daemon::Init and see if it then shows some warnings.

I didn't see anything obviously wrong in the perl script. Do you know where exactly serial communication fails? Does it fail at the initialization/connection phase or when  you try to write in the /dev/ttyUSB0? It may be easier to debug if you write a minimal version of the script that only initializes the serial port and writes to it. Try to catch all error messages and log them to syslog. If the script seem to silently die at some point, add the suspicious lines within an eval block and log the error message, e.g:

eval {
   $port = Device::SerialPort->new($portPath);
if ($@) {
    syslog(LOG_ERR, "Device::SerialPort->new failed: $@");

Btw, are you logged in as the same user (root?) when you run the perl script directly and when you try to execute is a service? What are the permissions/owner of /dev/ttyUSB0?

72  Using Arduino / General Electronics / Re: Solder diameter on: June 01, 2012, 07:13:06 am
Can't see the board either, but 1,5mm soldering wire is quite thick. For generic soldering (through hole components etc) 0,7mm - 1,0mm could be better choice. Thinner solder melts faster and it's easier to apply right amounts of solder.
73  Using Arduino / Programming Questions / Re: Any experience with run levels in linux and daemons? on: May 31, 2012, 12:59:01 pm
Please clarify what works and what doesn't. The actual perl script/daemon works when you run it in a terminal? The init script doesn't work when you try to start it using "service zoneswitch start", but what happens if you try to run the init script directly,  i.e., "/etc/init.d/zoneswitch start"? Do you get any error messages or does it fail silently? You could also post the init script and the perl code here.
74  Using Arduino / General Electronics / Re: Using Microsoft SideWinder 3D Pro as a joystick for our robot on: May 31, 2012, 08:29:47 am
You cannot use these modules as they are. They depend on the Linux kernel header files and APIs and the way they access the hardware is different. It may be feasible to port some parts of joy-sidewinder.c to the Arduino. Or at least you can use is as a template or reference for your own implementation.
75  Using Arduino / General Electronics / Re: Li-ion charger on: May 26, 2012, 02:37:39 am
So I decided to buy two MAX1811 and they are working fine charging two phone batteries (3.7V) with a 2.5W solar panel. The thing is, I would use both batteries in series for powering my rc car and I can only use one solar panel, i.e. both batteries would share the same ground from the solar panel. I think that's not possible, is it?
Is there a way I could use both batteries in series and still be able to charge them with one solar panel? Or if I put them in parallel and use a step-up for the arduino and rc car, would the charger ICs still do their job?
I would really appreciate any help.

Edit: forgot to link the datasheet.

Do you need to charge the batteries while driving the car? If you don't, you could build a circuit what switches the batteries from series to parallel when you plug in the charger.
Pages: 1 ... 3 4 [5] 6 7 ... 18