Show Posts
Pages: [1]
1  Using Arduino / Interfacing w/ Software on the Computer / Re: Serial.read() only works with Serial.print() on: May 15, 2013, 09:06:14 am
nevermind, I got it:

When I define the variables (all of them!) outside the function, it works as expected. No idea why it would need the Serial.print() otherwise..
2  Using Arduino / Interfacing w/ Software on the Computer / Serial.read() only works with Serial.print() on: May 15, 2013, 08:11:20 am
Hi,

I'm trying to send binary data to the arduino where I use the following code to determine when a packet starts and ends:

Code:
void readSerialString () {
  char in_char;
  char bin_buf[256]; // outgoing buffer
  int bytes_out = 0; // counter for filling bin_buf
  int pre_counter = 0;
  int pst_counter = 0;

    while (Serial.available() > 0) {
        if(bytes_out < 255) {
        in_char = Serial.read();

        Serial.print("......");        // why is this even necessary?

// state machine:

      if (pre_counter < 3) {
// no valid preamble found yet
        if (in_char == 'A') { // possible part of preamble found, increase counter
          pre_counter++;
        } else {
          pre_counter = 0;
        }
      } else {
// preamble complete, start pushing chars to buffer
        if (pst_counter < 3) {
          bin_buf[bytes_out++] = in_char;
          if (in_char == 'E') { // possible part of pst found, increase counter
            pst_counter++;
          }
        } else {
          do_something(bin_buf);
          pre_counter = 0;
          pst_counter = 0;
          bytes_out = 0;
         memset(&bin_buf, 0, 256);
        }
      }
    } else {
      memset(&bin_buf, 0, 256);
      bytes_out = 0;
    }
  }
}

Here comes the weird part:

This works, but only with the Serial.print("......"); statement. If I leave that out the Arduino doesn't even seem to read the serial buffer, let alone ever get to the do_something(bin_buf); statement. It doesn't seem to matter what characters are in the Serial.print() as long as there are at least six bytes.

I'm lost. Can anybody help?

Regards,

Ali
3  Using Arduino / Programming Questions / Re: atmega randomly drops into reset loop on: November 23, 2012, 08:14:11 pm
Just wanted to let you know, I think i figured it out:

It actually was the watchdog, or rather the way I implemented it. In the end all I had to do was add a line at the beginning of my setup() that reads "MCUSB = 0;". Without that the MCU would keep resetting itself when the watchdog triggered a reset. With this line present everything seems to work as intended.

The updated code is in my github repository:
https://github.com/alibenpeng/keyfob


Cheers,

Alexander
4  Using Arduino / Programming Questions / Re: atmega randomly drops into reset loop on: November 20, 2012, 05:01:37 am
Regarding the EEEPROM writes, I realize that the EEPROM can be written only 100.000 times, but as I said, these are for debugging only. Once I know what's going on I'll throw them out again. Also the flash can be written only 10.000 times, and at the rate I'm reflashing the device right now, I might easily hit that limit first. smiley-wink

Do you have anything connected to the reset pin? When the problem happens, do you still have a healthy steady voltage on the 5V pin? What are the symptoms that make you conclude it is resetting itself?

I have a 10k pullup to VCC and a 100nF to ground, as seen in the schematic. I haven't measured the voltage on the reset pin yet, I'll do that next time the bug strikes. The conclusion that it's resetting itself comes from the counters in the EEPROM: The counters for wakeup, sleep and button presses represent the actual number of times these events happened, while the reset counter is through the roof.

Apart from the number of EEPROM writes, I can see a few possible issues:

1. You are enabling the pin change interrupt before you configure the pins. Do it the other way round, i.e. set up the pins as inputs (and you could use INPUT_PULLUP mode instead of writing HIGH to the port), and only then enable the pin change interrupt.

2. As you are using the watchdog, you should reset and disable it at the beginning of setup().

In my experience, reset loops are usually caused by using the watchdog incorrectly.

1. I'll try changing the order of enabling the interrupt and enabling the internal pullups. I tried using INPUT_PULLUP but my version of Arduino does not seem to support it.

2. Ironically I used the watchdog because I suspected the process of setting up the RFM12 and sending my garage door opening sequence to hang (it takes quite long, about 300ms). Maybe I replaced one problem with another..

I'll try and do what you told me, but I don't really understand what that'll change exactly. Could you go a bit more into the theory behind that or point me to some documentation?
5  Using Arduino / Programming Questions / atmega randomly drops into reset loop on: November 19, 2012, 04:02:31 pm
Hi,

I've built this little switch to open my garage door, and most of the time it works alright, but sometimes it seems to get stuck and I have no idea where or why that happens. Schematic and sourcecode are attached.

All eeprom related commands are for debugging only. So far I found out that at some point the controller seems to start resetting itself until the battery dies.

These  are my fuse settings:
avrdude: safemode: lfuse reads as E2
avrdude: safemode: hfuse reads as D1
avrdude: safemode: efuse reads as 7

I don't really understand the startup time settings, so maybe there's something wrong with that.


Any help is appreciated!

Cheers,

Alexander
6  Topics / Science and Measurement / Re: ESR meter with Arduino on: October 30, 2012, 07:04:08 pm
I've built the circuit on a breadboard and it works fine. But for production use I'm aiming at eliminating the whole arduino and building a board with a stand alone atmega 328.

The problem is, I can't really decide on how to build the power supply:

I understand that a clean supply voltage is crucial, so just hooking up a 4*AA-battery-pack is out of the question.

But do I have to power the circuit with 5V or will 3.3V also work (with some adjustments to the code, of course)? And if so, can I use a switching regulator instead of a linear one?
The Arduino as well as other ESR-meter-projects (including Le Hung's) use linear regulators, so maybe using a switching regulator might not be a good idea, because of the ripple it might introduce. Then again, maybe this issue could be addressed with a few caps..

Any input on this is appreciated!

Cheers,

Ali
7  Topics / Science and Measurement / Re: ESR meter with Arduino on: October 21, 2012, 10:04:21 am
Hi,

I'd like to build this project but I don't seem to get the thing about the four wire connection to the DUT:

Why use four wires to connect a capacitor that has only two wires? Why not connect pin1 and pin2 of CN1 directly? I've seen other esr meters that use very short wires to connect to the DUT, is this something about wire capacities or something of this kind?

Also, in the original schematic by Le Hung there is an additional BS170 mosfet in the circuit, could anybody clear up what that is about?

I know how a esr-meter works in principle, but this really puzzles me.

Cheers,

Ali
Pages: [1]