Show Posts
Pages: 1 [2] 3
16  Using Arduino / Programming Questions / Re: Is there a way to control both frequency and duty cycle for PWM outputs? on: July 29, 2011, 07:53:48 pm
Thanks for all the replies! I'll look into all these possible solutions and let you know if I figure it out!
17  Using Arduino / Programming Questions / Re: Is there a way to control both frequency and duty cycle for PWM outputs? on: July 28, 2011, 12:17:30 pm
One more question: would it be fair to assume as long as I can generate the desired freuency from, say, Timer 2, I can then get PWM output based on that frequency?
18  Using Arduino / Programming Questions / Re: Email attachments from arduino as an SMTP client on: July 28, 2011, 12:15:17 pm
Oh cool, thanks Paul!
19  Using Arduino / Programming Questions / Re: Is there a way to control both frequency and duty cycle for PWM outputs? on: July 28, 2011, 12:14:26 pm
Hi GlitchBoy, thanks for the links, reading further, I'm going to look into this ... do you know how I can read and write to the TCCRxB timer registers?
20  Using Arduino / Programming Questions / Re: Email attachments from arduino as an SMTP client on: July 28, 2011, 11:57:53 am
Thanks for sharing RazorBlade! It's quite interesting to see that the Ethernet shield does not have a fixed MAC address which is really weird and makes it susceptible to MAC collissions (though I doubt anybody is doing MAC-based routing much anymore). What will probably happen is that we end up with everyone using all 00-00-00-00-00-00 as their MAC. I wonder if it might be an issue if you have multiple devices with the same MAC address on the same subnet though.

Also, does the Ethernet shield have existing libraries for DNS lookup and all that?

Finally, what's the bottleneck in this system? Ethernet is really fast so why would sending a 50KB picture take 30 seconds?

Sorry for hi-jacking this thread with n00b questions.
21  Using Arduino / Programming Questions / Re: Email attachments from arduino as an SMTP client on: July 27, 2011, 07:52:58 pm
Interesting problem. Obviously, the hardest part is to build the SMTP client state machine that implements something like section 4.2 in RFC 3030 (see link in reply by ManicDee). Assuming your SMTP server supports chunking, then all you have to do is the following:

1) Get the binary data of the image file as a stream of octets (bytes)
2) Invoke the state machine and follow the protocol (plus whatever cleartext auth needed) up until the BDAT part
3) Issue a BDAT for the size of the binary data (or send them in chunks)
4) Blast the binary data across the wire.
5) Issue a BDAT 0 LAST
6) Wait for confirmation of all data chunks, issue QUIT and close the connection.

You should be able to find C-based SMTP client code in the open-source realm and adapt it for the Arduino. In any case, sounds like quite a bit of work. Also, I would imagine it would be very, very hard to build an SSL stack on the Arduino.

Just my 2 cents' worth from a backseat commentator.  :-)
22  Using Arduino / Programming Questions / Is there a way to control both frequency and duty cycle for PWM outputs? on: July 27, 2011, 06:05:40 pm
Hi all, I'm wondering if there is a way to specify both the frequency (e.g. tone()) and duty-cycle (i.e. analogWrite()) for a PWM output? I'm looking into some quasi "frequency modulation" applications that requires that I control both the frequency and duty-cycle. Ideally, I'd like to use the functions in the standard library, if that's even possible.

Thanks in advance!
- K.
23  Using Arduino / Interfacing w/ Software on the Computer / Re: Generating unique ID for each sketch upload? on: July 05, 2011, 08:20:05 pm
Here's the code in a crude, preliminary form. I snipped out a lot of irreevant code so I might have introduced a few errors, but I'm sure folks can figure it out.

Code:
static int boardIdBaseAddress = 0;
static int timer = 0;
static byte b5 = 0;
static byte b6 = 0;
static byte b7 = 0;
static byte b8 = 0;

unsigned long setupEeprom()
{
  byte b1 = EEPROM.read(boardIdBaseAddress);
  byte b2 = EEPROM.read(boardIdBaseAddress + 1);
  byte b3 = EEPROM.read(boardIdBaseAddress + 2);
  byte b4 = EEPROM.read(boardIdBaseAddress + 3);
  b5 = EEPROM.read(boardIdBaseAddress + 4);
  b6 = EEPROM.read(boardIdBaseAddress + 5);
  b7 = EEPROM.read(boardIdBaseAddress + 6);
  b8 = EEPROM.read(boardIdBaseAddress + 7);
 
  if ((b1 != 'A') || (b2 != 'P') || (b3 != 'P') || (b4 != '1') || ((b5 == 0xff) && (b6 == 0xff) && (b7 == 0xff) && (b8 == 0xff)))
  {
    b1 = 'A';
    b2 = 'P';
    b3 = 'P';
    b4 = '1';
    randomSeed(timer);
    b5 = random(256);
    b6 = random(256);
    b7 = random(256);
    b8 = random(256);
    EEPROM.write(boardIdBaseAddress, b1);
    EEPROM.write(boardIdBaseAddress + 1, b2);
    EEPROM.write(boardIdBaseAddress + 2, b3);
    EEPROM.write(boardIdBaseAddress + 3, b4);
    EEPROM.write(boardIdBaseAddress + 4, b5);
    EEPROM.write(boardIdBaseAddress + 5, b6);
    EEPROM.write(boardIdBaseAddress + 6, b7);
    EEPROM.write(boardIdBaseAddress + 7, b8);
  }
}

void loop()
{

  // ...

  if (computer_asks_for_ID)
  {
    setupEeprom();

    // ID will be in b5, b6, b7, b8
    send_to_computer(b5, b6, b7, b8);
  }

  // ...

  timer++;
}
24  Using Arduino / Interfacing w/ Software on the Computer / Re: Generating unique ID for each sketch upload? on: July 04, 2011, 04:27:15 pm
Quote
The reference does suggest using randomSeed(analogRead(0)) (or some unused analog input).

On a 328 you also have analog(smiley-cool to measure internal temperature, but it is not reliable random - http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1294239019 - but it might be good enough for your application. It won't cost you a free pin as it is internall so allways free....

If your application has a ethernetshield you might consider fetching the serial number from a simple PHP script on a local website or a randomnumber from www.random.org.

Imho: Sometimes it is much easier to solve things with some extra tools than try to build it all in one sketch.

Thanks Rob, I think I got a workaround for my particular implementation. Since the ID is not needed until the computer first asks for it, I moved it from setup() to loop() and deferred the EEPROM setup code until the computer requests it. I also implemented a crude counter inside loop(), and used the loop count as the randomSeed() when the EEPROM setup code is run, so it is almost impossible that two different bords will call randomSeed() at the excat same loop count. I think that's good enough for my purposes.

Appreciate everyone's help.
25  Using Arduino / Interfacing w/ Software on the Computer / Re: Generating unique ID for each sketch upload? on: July 04, 2011, 02:26:23 pm

Problem with the random generator is that it is not so random at all, it is an algorithm and unless every sketch has an unique seed you will get the same signature for every board.

Furthermore if your boards have used the EEPROM before (or in a factory test who knows) your code will probably not write your signature, so you need an erasor sketch that writes 0xFF to EEPROM first otherwise previous values could be identical ... AVRdude can also do that.

It is quite hard to make this process automatic AND robust (failproof). I think I would use some makefile with AVRdude to write the signature to EEPROM after uploading the sketch, and that makefile would increment the EEPROM file every time called. It can keep track of the numbers applied on which day etc.
Or let some SED command change a signature in the source to some sequence number.

How many boards do you intend to label this way?
Rob

Hi Rob, I agree this is a hard problem to have a robust solution. The reference does suggest using randomSeed(analogRead(0)) (or some unused analog input). I did notice some noise in the unused analog input but the noise is minimal (+/-5) so collision is likely, plus you need an unused analog input.

To solve the issue with pre-existing values in the EEPROM, I added another EEPROM header that contains a 4-byte signature header that identfies this sketch(e.g. "APP1") so I can at least tell if my sketch was the last one to write to these bytes. If the header doesn't match, then I generate new values.

All-in-all, the hardest paroblem to solve is the run-time random number generation, and I don't want to depend on any external tools, if possible at all.

Thanks,
- K.
26  Using Arduino / Interfacing w/ Software on the Computer / Re: Generating unique ID for each sketch upload? on: July 04, 2011, 01:38:18 pm
A few weeks ago we had the discussion how to put the sourcecode of a sketch into the Arduino. This ended in adding a unique reference to the source in the code by means of an UUID which is in fact just a 16 bytes unique number. See - http://arduino.cc/forum/index.php/topic,64193.15.html - for the whole discussion.

This technique might be usefull for you. I have not tried to access the UUID array from the sketch, should be possible as it is just access to progmem ...

Rob

Thanks Rob. I actually needed something more than a UUID to identify a sketch. I need to persist a relatively unique ID for each COPY of the sketch that is uploaded to a board. For example, if I upload the same sketch to 10 boards, I need each board to have a relatively unique ID.

Turns out the EEPROM is quite useful for this. It will set an ID in the on-board EEPROM if it had not been set before. I felt a 4-byte value would be good enough since I only needed a relatively unique value. Here's the snippet of code I wrote in case anyone is interested. I just put it in the setup() function - use at your own risk!!

Code:
#include <EEPROM.h>

static int boardIdBaseAddress = 0; // or whatever you want

unsigned long setupEeprom()
{
  byte b1 = EEPROM.read(boardIdBaseAddress);
  byte b2 = EEPROM.read(boardIdBaseAddress + 1);
  byte b3 = EEPROM.read(boardIdBaseAddress + 2);
  byte b4 = EEPROM.read(boardIdBaseAddress + 3);
 
  if ((b1 == 0xff) && (b2 == 0xff) && (b3 == 0xff) && (b4 == 0xff))
  {
    b1 = random(256);
    b2 = random(256);
    b3 = random(256);
    b4 = random(256);
    EEPROM.write(boardIdBaseAddress, b1);
    EEPROM.write(boardIdBaseAddress + 1, b2);
    EEPROM.write(boardIdBaseAddress + 2, b3);
    EEPROM.write(boardIdBaseAddress + 3, b4);
  }
}

PS: Of course, this function is no-longer sketch-specific. It just persists a random 32-bit (unsigned long) value to any board the first time it's run. Also, if these slots have been set by another sketch before, it might just use whatever existing values in the EEPROM. You can add your own sketch signature to the EEPROM and verify that the value was indeed set by your sketch.

PPS: Is the any pre-defined usage for the EEPROM bytes, or does the sketch have full reign over every available byte in the EEPROM?
27  Using Arduino / Interfacing w/ Software on the Computer / Re: Generating unique ID for each sketch upload? on: July 03, 2011, 07:33:19 pm
For those who are interested - I found the EEPROM library information. Looks like the initial byte value for uninitialized EEPROM memory is 0xff (255) so that's very useful.

http://arduino.cc/en/Reference/EEPROMRead
28  Using Arduino / Interfacing w/ Software on the Computer / Re: Generating unique ID for each sketch upload? on: July 03, 2011, 07:20:30 pm
Could using the on chip EEPROM memory be a part of a solution?

Thanks Frank and retrolefty!

YES! Can the sketch code access the EEPROM during run time?  If it has a known factory initial value (e.g. 0), then the code can initialize it to a random number if it sees the initial value during the setup() phase. That would be about perfect!!
29  Using Arduino / Programming Questions / Re: What happens when I digitalRead() a pin that is in PWM output mode? on: July 03, 2011, 11:42:16 am
I'd expect it to output 1 if the write value is anything but zero, like the digitalWrite() behavior.
30  Using Arduino / Interfacing w/ Software on the Computer / Generating unique ID for each sketch upload? on: July 03, 2011, 11:31:37 am
Hi all, not sure where this question belongs, but this seems like good place, though technically, this is more of a compiler/upload feature question.

Is there a way to set a different unique ID every time I upload the firmware to a board? The ID needs to be accessible from the C code of course. Essentially I want to write a unique identfier to every board that I upload a sketch to so I can identify the boards consistently from the computer (not a fixed value that I hard-code in the sketch for every board). Using the serial port name is not good enough because that can change as the boards are unplugged and plugged in again.

Any tricks / ideas out there?

Thanks,
- K.
Pages: 1 [2] 3