Show Posts
Pages: 1 ... 26 27 [28] 29 30 ... 36
406  Using Arduino / Programming Questions / Re: Best practice for digitalWrite() on: June 22, 2012, 07:42:40 pm
Neither sketch ever actually assigns a value to turnMeOn, so neither will ever actually turn the pin on.

I didn't intend to put a complete working sketch, I just wanted enough code so my question was clear.
407  Using Arduino / Programming Questions / Best practice for digitalWrite() on: June 22, 2012, 07:23:16 pm
If I want to turn something on with digitalWrite() there are two ways I can code this.  I'm wondering if one is preferable to the other. 
The first method is to execute the digitalWrite() command in every loop of the sketch, like this:
Code:
void loop()
{
  static bool TurnMeOn;
  if(TurnMeOn == true)
  {digitalWrite(MyPin, HIGH);}
  else
  {digitalWrite(MyPin, LOW);}
}

The second is to turn the output on once, and not do it every loop. For example:
Code:
void loop()
{
  static bool TurnMeOn;
  static bool OutputIsOn;
  if(TurnMeOn == true && OutPutIsOn == false)
  {
    digitalWrite(MyPin, HIGH);
    OutPutIsOn = true;
  }
  else
 {
  digitalWrite(MyPin, LOW);
  OutPutIsOn = false;
 }
}
Does is make any difference between these two methods?

408  Using Arduino / Networking, Protocols, and Devices / Re: Leonardo Digital Pins 0 and 1 on: June 18, 2012, 07:00:07 am
Thanks.  I know nothing about serial interface, but I do have a project that uses an xbee.  I wonder if there is any advantage of using pins 0 and 1 with the xbee.  If so, I'm assuming a library would have to be written to take advantage of the UART.
409  Using Arduino / Networking, Protocols, and Devices / Leonardo Digital Pins 0 and 1 on: June 17, 2012, 10:19:39 pm
Looking at the Leonardo info, it seems it doesn't use digital pins 0 and 1 anymore, at least not by default.  I just wanted to double check - can I now use these pins for my sketches?
410  Using Arduino / Installation & Troubleshooting / Re: Leonardo doesn't send to Serial Monitor after software reset on: June 17, 2012, 10:06:16 pm
I'm surprised that it doesn't work when you use the watchdog timer.  Can you provide more details (e.g. a sample sketch and the behavior you see)?

Attached is my sketch.  The watch dog timer is disabled, you'll need to uncomment // #define WDT on line 17 of Humidity_716Basement_v2.ino to enable the WDT.
411  Using Arduino / Installation & Troubleshooting / Leonardo doesn't send to Serial Monitor after software reset on: June 16, 2012, 04:44:43 pm
I have Arduino 1.01 and a Leonardo with an Ethernet shield (R3).  My sketch is designed to do a reset if there is a communication problem, to test this I just unplug the cable from the Ethernet shield.  The Arduino resets using  asm volatile ("  jmp 0"); 
The reset works fine and the Arduino continues uploading to COSM.com via the Ethernet shield, but if I had the serial monitor open, I don't see any text after the reset.  Even if I close the serial monitor and re-open it, still nothing.  I know the Leonardo works a little differently then the UNO with the serial monitor.  Is there anything I can do to get the Arduino to recognize the serial monitor after a reset.  The serial monitor works fine when I upload a new sketch, it's just after a reset I have a problem.  I had also tried resetting with the Watch Dog Timer, and I have the same serial monitor issue with that method also.  If I close the serial monitor then do a hard reset (using the PCB pushbutton), the serial monitor works again.

412  Using Arduino / Programming Questions / Re: strncpy() causes reset on: April 18, 2012, 11:40:53 am
You should move your Serial.print strings to PROGMEM.

A lazy way is to use the Serial.print(F("ahaqoihio"));
Unless every output string is unique you are duplicating strings in PROGMEM.

I'm going to do that.  I learned a lot about strings and RAM in trying to debug this problem.
413  Using Arduino / Programming Questions / Re: strncpy() causes reset on: April 18, 2012, 08:05:45 am
I'll never understand why Microsoft invented a bunch of complex templates for casting, and why anyone uses them.

Code:
char *reply = (char *)(ether.tcpReply(session));

No templates; smaller footprint; easier (for me) to understand.

I like your method better. 
414  Using Arduino / Programming Questions / Re: strncpy() causes reset on: April 17, 2012, 10:03:15 pm
I got it working.  I shortened a bunch of strings in my Serial.print() statements and that freed up some RAM.

I also figured out how to cast my const char to char:
char* reply = const_cast<char*> (ether.tcpReply(session));

I'm not changing the reply string, so I felt comfortable doing this.
415  Using Arduino / Programming Questions / Re: strncpy() causes reset on: April 17, 2012, 07:53:26 am
It looks like I'm running out of RAM.  I added a FreeMemory routine I found here: http://arduino.cc/playground/Code/AvailableMemory

Before I define reply2, I have less then 200 bytes.  reply2 would be 308 bytes.   I'd like not have to create reply2 and just use reply with strtok(), but reply is a const char and strtok() doesn't like that.  So my solution is to strncpy reply to reply2.   

I think I'm running out of ram when I define reply2 on line 451.

I would also like to free up some ram, but I'm not sure how to do that.   Attached is the entire sketch, except for PachubeAPIKey.h which is just a #DEFINE with my API key (65 characters).

I'm using a Nanode, which is similar to Arduino Deumilanove.
416  Using Arduino / Programming Questions / Re: strncpy() causes reset on: April 17, 2012, 06:54:44 am
Quote
I want to use strtok (using \n as delimiter) to parse each line, but first I'm using strncpy() to prevent a
a invalid conversion from 'const char*' to 'char*'
The proper cast would prevent the "problem" without the need to copy the string.

How do I do that?
417  Using Arduino / Programming Questions / Re: strncpy() causes reset on: April 17, 2012, 12:26:06 am
Oops, I should have used:
Code:
strncpy(reply2, reply, strlen(reply))

I made this change but it still reboots.  I don't know about running out of memory.  How do I tell?  When I compile it says Binary Sketch:  18,082 bytes (of a 30,720 byte maximum)
418  Using Arduino / Programming Questions / strncpy() causes reset on: April 16, 2012, 10:14:14 pm
I'm trying to take parse the HTTP reply I get from uploading data to pachube.com.  I'm using EhterCard.h and it has a function tcpReply() that returns the HTTP response, which is

HTTP/1.1 200 OK
Date: Fri, 13 Apr 2012 12:17:36 GMT
Content-Type: text/plain; charset=utf-8
Connection: close
X-Pachube-Logging-Key: logging.Lo55opRx5dl5UwAw2NUO
X-PachubeRequestId: 2ea1be6efb47aac0a0f47ec04196b14f721f605c
Cache-Control: max-age=0
Content-Length: 1
Age: 0
Vary: Accept-Encoding


According to strlen() it's 308 bytes long.  I want to use strtok (using \n as delimiter) to parse each line, but first I'm using strncpy() to prevent a
a invalid conversion from 'const char*' to 'char*'

But my sketch seems to be failing at the strncpy() function and reboots before I even get to strtok().  Below is my code, can anyone tell me what I am doing wrong?

Code:
 
  const char* reply = ether.tcpReply(session);    // part of EtherCard.h library
  if (reply != 0)
  {
    char reply2[strlen(reply)+1];
    strncpy(reply2, reply, sizeof(reply));  // I think Arduino is rebooting here
    reply2[strlen(reply)] = '\0';
   
    char delims[] = "\n";
    char *result = NULL;
    result = strtok( reply2, delims );
    while( result != NULL )
    {
        Serial.println(result);
        result = strtok( NULL, delims );
    }
  }
419  Using Arduino / Motors, Mechanics, and Power / Re: How would I unlock my door? on: April 05, 2012, 08:01:21 pm
You might find this interesting, it's an Arduino that listens to you knocking on the door and if you know the right pattern, it opens the door.


420  Using Arduino / Project Guidance / Re: How To Detect Bluetooth ID on: April 05, 2012, 07:53:38 pm

It's fun when I get to repeat myself.

1. The iPhone doesnt stay in discoverable mode unless initiated by the settings screen.
2.  The iPhone doesn't support the serial profile, so your device won't automatically see your the phone when it is in range.

If you can use a Bluetooth device that supports the HID profile, you might have better luck...

I was hoping that since I'm not really trying to communicate or pair with the iphone (just detect and ID), some of these limitation may still let me get my project to work.  But it sounds like I should wait for a Bluetooth 4.0 shield.  Instead of using bluetooth to unlock the door, maybe I'll just use the thumbprint reader that Adafruit just came out with.  I like the bluetooth project a lot.  I think it would be really cool if a door unlocked as I approached.  But I'm not going to switch phones just for this.
Pages: 1 ... 26 27 [28] 29 30 ... 36