Loading...
  Show Posts
Pages: [1] 2 3 ... 5
1  Using Arduino / Interfacing w/ Software on the Computer / Re: Arduino serial read in script keeps hanging. Ideas? on: September 04, 2012, 03:52:17 pm
I never found the root cause.  I hacked some code together that can spot the problem.

reader.sh
Code:
#!/bin/bash
TMP_DATE="/dev/shm/tmp.date.txt"
date +%s > $TMP_DATE

while read CHAR
do
  echo "${CHAR}" | logger
  date +%s > $TMP_DATE
done < /dev/ttyUSB0

watcher.sh (Setup to run from cron once a minute)
Code:
#!/bin/bash
#Version=0.5

HOME_PATH="/root/bin"
SCRIPT="serial_watcher.sh"
FULL_PATH="${HOME_PATH}/${SCRIPT}"
TMP_DATE="/dev/shm/tmp.date.txt"

#Check:  Has it run in the last 7min (420 sec)
CURRENT_TMP_DATE=`date +%s`
LAST_WRITTEN_DATE=`cat $TMP_DATE`
DIFF=$(($CURRENT_TMP_DATE - $LAST_WRITTEN_DATE))

if [ $DIFF -gt 420 ];then
  logger "$0 ERROR: $SCRIPT has not responded in $DIFF seconds, restarting"
  killall $SCRIPT
  nohup $FULL_PATH &
fi
2  Using Arduino / Interfacing w/ Software on the Computer / Re: Arduino serial read in script keeps hanging. Ideas? on: August 29, 2012, 03:03:52 pm
PC end XBee is attached to a XBee Explorer
https://www.sparkfun.com/products/8687

As far as the lights?  The XBee/Arduino sleep 99% of the time, and the lights are out (Both sides).  When it does wake up, for about 3 seconds, both sides light up, and the RX/TX lights show a burst of activity.

If I switch back to my 2.4GHz XBee's everything works (No code changes).  I am guessing I am getting some kind of control charter that is causing my while loop to crash.  But I cant see what that control charter is do to the crash... Nasty catch 22.
3  Using Arduino / Interfacing w/ Software on the Computer / Arduino serial read in script keeps hanging. Ideas? on: August 29, 2012, 10:17:18 am
I have a solar powered Arduino Fio out in a field playing weather station.  All the data is get transmitted back over a XBee net.  Last week I upgraded from XBee 2.4GHz's to XBee 900's.  Now my serial_watcher.sh script crashes/hangs ever 4~6 hours. 

serial_watcher.sh
Code:
#!/bin/bash

while read CHAR
do
  echo "${CHAR}" | logger
done < /dev/ttyUSB0

In a crashed state the script is still running, but no data is coming in.
Code:
# ps -ef | grep serial
root     13147     1  0 Aug28 ?        00:00:23 /bin/bash /root/bin/serial_watcher.sh

I am stumped on this one.  Nothing in dmesg/messages.  Yet is works fine for weeks on end with a 2.4GHz XBee.
If I restart my script every thing start working again, for a few hours.
Code:
# kill 13147
# nohup /root/bin/serial_watcher.sh &

XBee 2.4GHz
https://www.sparkfun.com/products/8710

XBee 900
https://www.sparkfun.com/products/9098

Any ideas?
4  Using Arduino / Programming Questions / Hardware interrupt with a 555 Timer, or internal timer, with a sleeping arduino? on: July 20, 2012, 03:50:37 pm
Question:
Is it possible to use a timer to wake an Arduino once every 5 minutes, regardless of how long the code takes to run?  I know I can do this with a hardware interrupt and 555 timer set to pulse once every 5 minutes, but I would rather not add extra hardware.

What I have:
Execute code --> Sleep 5m = 5m + execution time for each cycle

What I would like:
Start 5m timer, Execute code and go to sleep, sleep until the 5m timer expires = 5m for each cycle, regardless of execution time

The setup:
I have an Arduino Fio (V2) attached to N number of DS18S20 temperature sensors. The Fio is solar/battery powered and transmits data back home via XBee. The Fio/XBee are set to deep sleep for about 5 minutes between reads. I would like new data every 5 minutes (+/- a few seconds).  With the addition of each DS18S20 the sampling time goes up. I am using the Arduino Narcoleptic http://code.google.com/p/narcoleptic/ code to put my Fio to sleep. My current watt draw when asleep is less then any meter I own can read. :-)

My current sleep code is rather dumb
Code:
//28 = about 5min including code execution time
for (int i=0; i < 27; i++)
{
  Narcoleptic.delay(10000); 
}

Any ideas on how to do this with out adding hardware?
5  Forum 2005-2010 (read only) / Syntax & Programs / Re: How do I set TCNT2 for XXXXX Hz (Solved) on: November 21, 2010, 10:33:46 pm
We have gotten off topic.  The timer code worked great.
6  Forum 2005-2010 (read only) / Syntax & Programs / Re: How do I set TCNT2 for XXXXX Hz on: November 20, 2010, 05:40:47 pm
Setting up Analog pin 5 as an interrupt pin...
Code:
void setup()
{  
  //make analog pins 5 into a pin change interrupt
  PCICR |= (1 << PCIE1);
  PCMSK1 |= (1 << PCINT12)
}

ISR( PCINT1_vect )
{
  digitalWrite(ledPin, HIGH);
}

This should work.  Will do testing soon.
7  Forum 2005-2010 (read only) / Syntax & Programs / Re: How do I set TCNT2 for XXXXX Hz on: November 20, 2010, 03:28:12 pm
Quote
Most Arduino boards have two external interrupts: numbers 0 (on digital pin 2) and 1 (on digital pin 3).

PORTD=0~7....  CRAP!
8  Forum 2005-2010 (read only) / Syntax & Programs / Re: How do I set TCNT2 for XXXXX Hz on: November 19, 2010, 11:30:38 pm
I love open source.  There are many people who have many different ways to solve this problem.
http://blog.makezine.com/archive/2008/05/makeit_protodac_shield_fo.html
http://interface.khm.de/index.php/lab/experiments/arduino-dds-sinewave-generator/
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1208192843

At this point in time, I think I have the fastest solution.  If I push the i++, and the i==0 into asm, I will have the fastest solution.

It does not really matter, as I do not need to run at 15.99MHz  :-)

I am really looking forward to my new scope.  Once I have that, I can place numbers on all this, and see what I need to change. Until then, I am just messing with the serial functions.
9  Forum 2005-2010 (read only) / Syntax & Programs / Re: How do I set TCNT2 for XXXXX Hz on: November 19, 2010, 10:27:15 pm
Counting cycles across my old scope's screen.
With the old code I could get a max of 1.75 complete cycles.
With the new code I get 5.5 cycles. I can get 9 cycles when I remove the 'for' loop!

So It would seem that the 'for' loop is costly! It may be a better move to use a much bigger wave table and vary the number of cycles in the wavetable in order to achieve different speeds.

Code:
//byte wavetable[32] = {128, 154, 178, 201, 220, 236, 247, 254, 255, 251, 242, 228, 211, 190, 166, 141, 115, 90, 66, 45, 27, 14, 5, 1, 3, 9, 20, 36, 56, 78, 103, 128};
byte wavetable[32] = {0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255};
byte delay_length = 0;
byte i = 0;
unsigned int z = 0;

void setup()
{
  for (z = 0; z <= 7; z++)
  {
    pinMode(z, OUTPUT);
  }
}

void loop()
{  
  PORTD=wavetable[i];

  i++;
  if (i==32)
    i=0;  
  else
    asm("nop\n nop\n nop\n");  

  /*for (z = 0; z <= delay_length; z++)
  {
    asm("nop\n");
  }*/
}
10  Forum 2005-2010 (read only) / Syntax & Programs / Re: How do I set TCNT2 for XXXXX Hz on: November 19, 2010, 04:27:59 pm
Slight code change.  Defining z as a global variable.  Dont want to define a new z every time "for (byte z = 0; z <= delay_length; z++)" is called.
11  Forum 2005-2010 (read only) / Syntax & Programs / Re: How do I set TCNT2 for XXXXX Hz on: November 19, 2010, 04:20:33 pm
If a single wave form is defined by 32 points.  How fast do you think we can go?
Code:
byte wavetable[32] = {128, 154, 178, 201, 220, 236, 247, 254, 255, 251, 242, 228, 211, 190, 166, 141, 115, 90, 66, 45, 27, 14, 5, 1, 3, 9, 20, 36, 56, 78, 103, 128};
byte i = 0;
byte delay_length = 0;

void setup()
{
  for (byte z = 6; z <= 13; z++)
  {
    pinMode(z, OUTPUT);
  }
}

void loop()
{  
  PORTD=wavetable[i];

  i++;
  if (i==32)
  {
    i=0;
  }
  else
  {
    asm("nop\n nop\n");
  }

  for (byte z = 0; z <= delay_length; z++)
  {
    asm("nop\n");
  }
}
12  Forum 2005-2010 (read only) / Syntax & Programs / Re: How do I set TCNT2 for XXXXX Hz on: November 19, 2010, 04:05:12 pm
Quote
connecting a digital pin on the RX Arduino to a digital pin on the TX Arduino
That was EXACTLY what I was planning.  :-)

Quote
millis, micros, delay, delayMicroseconds (I think) will all stop running
 That is just fine, I can write my own delay function.
13  Forum 2005-2010 (read only) / Syntax & Programs / Re: How do I set TCNT2 for XXXXX Hz on: November 19, 2010, 01:46:53 pm
I need to look at the assembly code for i=0, and replace the i=i with the correct amount of clock cycles:
Code:
asm("nop\n nop\n nop\n nop\n");
I can also use an assembly based delay, if I need less over head.  If need be I can write the whole delay in assembly.
Code:
for (int z =0; z <= foo; z++)
{
  asm("nop\n");
}

Quote
The other potential problem is the Timer 0 (millis) interrupt service routine.  At seemingly random points it will run and interfere with loop.

Can I just shutdown timer0?  Or will I break other stuff?
14  Forum 2005-2010 (read only) / Syntax & Programs / Re: How do I set TCNT2 for XXXXX Hz on: November 19, 2010, 10:53:13 am
Lets see if I can describe this all correctly. Two Arduino's; one for signal generation(TX), and one for signal comparison(RX).

In a metal detector there are two coils in the search head.  The transmission coil sends out the signal produced from TX Arduino that we have been working on. The receiver coil picks up any signal that a peace of metal is making. There are hardware amps on both the TX/RX signals.

The RX Arduino has a few jobs, compare and report the two different between signals, watching both the coils at the same time.  It takes the difference and outputs it over bluetooth to an Android based phone, where MUCH more power is available for real DSP.

A serial event comes into play when the use (Me), wants to change the frequency of the TX Arduino, or the shape of the wavetable. The user inputs the new data setting and they are transmitted via bluetooth to the RX Arduino.  In turn the RX Arduino will send the data set to the TX Arduino.

I hope this cleared up more questions then it made.  For more details on the metal detector side, please see: http://www.geotech1.com/forums/showthread.php?p=119001&posted=1
15  Forum 2005-2010 (read only) / Syntax & Programs / Re: How do I set TCNT2 for XXXXX Hz on: November 18, 2010, 11:58:24 pm
Really, is it this simple?!
Code:
byte wavetable[32] = {128, 154, 178, 201, 220, 236, 247, 254, 255, 251, 242, 228, 211, 190, 166, 141, 115, 90, 66, 45, 27, 14, 5, 1, 3, 9, 20, 36, 56, 78, 103, 128};
byte i = 0;
byte delay_length = 50;

void setup()
{
  for (byte z = 6; z <= 13; z++)
  {
    pinMode(z, OUTPUT);
  }
}

void loop()
{  
  PORTD=wavetable[i];

  i++;
  if (i==32)  //The real question... exact same run time in both cases?
  {
    i=0;
  }
  else
  {
    i=i;
  }

  delay(delay_length); //This may need to be an ASM `nop`
}

Need to do some scope testing to figure out what the speeds look like.
Pages: [1] 2 3 ... 5