Show Posts
Pages: 1 ... 100 101 [102] 103 104 ... 304
1516  Using Arduino / Programming Questions / Re: Start (Momentary) Button, safety on: May 10, 2013, 05:37:13 am
At the end of setup (a bit of pseudocode here)

while (start_button_ not_ pressed());

I made it a function call so you can add debounce and be sure against falsing.
You -can- just have a digitalRead(pin) if you don't believe in Murphy.

1517  Using Arduino / Programming Questions / Re: Compile errors with Progmem on: May 10, 2013, 05:30:20 am
A little surfing got me here:
http://www.controllerprojects.com/2011/05/23/determining-sram-usage-on-arduino/

And I grabbed the function:
Code:
int freeRam () {
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}

After yet another try getting #ifdef to work (this time using 1.03, last time using 0023) I said screw it and made two versions of a sketch to check what I can:

This one uses PROGMEM and reports 1811 bytes free on my UNO using IDE 1.03.
Code:

#include <avr/io.h>
#include <avr/pgmspace.h>

const char PROGMEM textTable[] = { // all this text stored in flash
  "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\0"
};

PGM_P tT; // will point into namesTable

/*
const char textTable[] = { // all this text goes into RAM
  "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\0"
};
*/

void  printProgstring( PGM_P FM )
{
  char fb;
  do
  {
    fb = pgm_read_byte( FM++ );   
    if ( fb )  Serial.print( fb );
  }
  while ( fb );
}


int freeRam () {
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}

void setup(void)
{
  Serial.begin( 9600 );
  Serial.print( "\nRAMSIZE_P Free RAM = " );
  Serial.print( freeRam());
  Serial.println( "\n" );

  tT = textTable;
  printProgstring( tT );
//    Serial.println( textTable );   
    Serial.println( );   
}

void loop(void)
{
}

This one uses RAM and reports 1523 bytes free on my UNO using IDE 1.03.
Code:
#include <avr/io.h>
#include <avr/pgmspace.h>

/*
const char PROGMEM textTable[] = { // all this text stored in flash
  "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\0"
};

PGM_P tT; // will point into namesTable
*/

const char textTable[] = { // all this text goes into RAM
  "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\0"
};

/*
void  printProgstring( PGM_P FM )
{
  byte fb;
  do
  {
    fb = pgm_read_byte( FM++ );   
    if ( fb )  Serial.print( fb );
  }
  while ( fb );
}
*/

int freeRam () {
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}

void setup(void)
{
  Serial.begin( 9600 );
  Serial.print( "\nRAMSIZE_R Free RAM = " );
  Serial.print( freeRam());
  Serial.println( "\n" );

//  tT = textTable;
//    printProgstring( tT );
    Serial.println( textTable );   
    Serial.println( );   
}

void loop(void)
{
}

1518  Community / Bar Sport / Re: Arduino based replicator on: May 10, 2013, 02:13:32 am
You wrote a bit more than that and it was aimed politically.

As written the new laws can't succeed, that seems evident. But the situation shaped by the old laws which still dominates has grown into a monster of enormous proportions, a capitalistic cancer of sorts (as opposed to capitalistic bone, muscle, and brains) with whole industries feeding off the easy money side and fighting like hell to keep their ride going.

The new law is the crippled child of people trying to fix the old system and people who did and still do everything they can to kill it and get back to something that can be used to bring about the soul-ugly form of Social Darwinism that was practiced over 100 years ago and brought about such things as Company Towns, child labor, crushing poverty of whole segments of society in ways that school children are only shown the edges of. You know, the kind of things that Ayn Rand fans salivate over.

But the new law shows that change -can- happen even after decades of NO.

And for a while we're going to have both new and old ways and pay the price of both. You can't get off your butt without some effort. Too bad the same ones screaming about the cost of such effort being the same ones undermining it with loads of support from a large cigarette smoking bad diet eating high cancer risk morons in government supplied powered wheelchairs living on social security and/or welfare and medicaid expecting full treatment for their future health needs even as they protest "big government" and swap lies about it. 

Yah, let's keep people away from preventative medicine because of the cost and then when they get desperately sick there will be a choice of giving them operations at astronomical prices or dumping them somewhere to die while acting sorry there's no money. But perhaps a family member can sell a kidney to someone who needs one and has money to pay and eventually that silly law against euthanasia can be struck down and we'll have some -real- progress in solving the population problem.
Does that sound like a plan? Because from what I see that IS the direction a lot of people are pushing and the Tea Party CHEERS at the mention of letting people who don't have health insurance die is a f__king good indicator of just that.

So lets see what it takes to break the grip of the NO people and get something that can work going?
 
I can't see how the pay-as-you-go right wing fundamentalists can accept the concept of insurance at all anyway. One cancer operation costs more than 'reasonable' insurance payments over 20 years even if the person with the cancer never took a penny out the whole time. That means that, oh gasp horrors, SOMEONE ELSE PAYS and maybe there won't be money for their cancer or dementia or other care. And that's just the start. What about the people that pay in all their life and die before they get sick? What about children born with illness or defects? Any Rand would say either kill them or let them die as long as it is THEM.

Yeah I 'get political' as a reaction to the crap going on. The brownshirts are marching and I certainly do speak out against them. I am not sheeple. I am not a cow. I am not a facist. I can think past my own immediate interests and see that that crowd certainly do not. You LIKE where they're headed then go ahead and support them but no way I sit still and shut up over it.
1519  Using Arduino / Programming Questions / Re: Compile errors with Progmem on: May 09, 2013, 04:40:25 pm
I have some confusion here of my own. The below is speculation.

Some thinking and I feel that if you access the data with a program space pointer then it should be program space data. But that leaves me wondering how come my code seems to work when it violates at least one rule in that article.

Quote
dataType PROGMEM variableName[] = {};   // not this one

Some answer to that is here in the pgmspace library doc.
Code:
Typedefs
typedef void PROGMEM prog_void
typedef char PROGMEM prog_char
typedef unsigned char PROGMEM prog_uchar
typedef int8_t PROGMEM prog_int8_t
typedef uint8_t PROGMEM prog_uint8_t
typedef int16_t PROGMEM prog_int16_t
typedef uint16_t PROGMEM prog_uint16_t
typedef int32_t PROGMEM prog_int32_t
typedef uint32_t PROGMEM prog_uint32_t
typedef int64_t PROGMEM prog_int64_t
typedef uint64_t PROGMEM prog_uint64_t

typedef dataType attribute alias
bang?

Note that PROGMEM appears to be an attribute like private, public or protected are. It is then that I see "prog_int8_t" is the same as "int8_t PROGMEM". If that is right then there's no need to use prog_int8_t and PROGMEM together, is there?

 
1520  Using Arduino / Programming Questions / Re: Delay function on: May 09, 2013, 01:54:00 pm
was wondering is it possible to write delay(1*60*100); or it should be written has delay(60000);?

The compiler will pre-calculate constant math and use the result. The first there will become as delay(6000);

You should take Keith's advice to heart. BWD shows a lesson that will allow you effectively do more than one thing at a time with Arduino.
1521  Using Arduino / Programming Questions / Re: Accelerometer (gy-521) to measure velocity and Force on: May 09, 2013, 01:34:31 pm
When he wrote "electronic football" I thought the ball was virtual and the kick vector was gyro/accelerometer readings.

Instrument the ball has problems of its own. Where will the sensors, controller, etc, be?

There was a time when you would take a delayed exposure picture of the ball moving lit only by a strobe light with a grid in the background, but hey that worked great.

1522  Using Arduino / Programming Questions / Re: Changing 'Handshake' Pin on: May 09, 2013, 01:23:30 pm
The handshake pin sounds more like SS (slave select) or CS (chip select) which is what you have to bring low for the slave to take data from the SPI bus.

CS can be one slave at a time or it can be daisy-chained to run many SPI devices in concert, like shift registers acting as one.

When you say both at the same time, I get a picture that it's actually one at a time for very short periods perhaps moving 32 to 512 bytes from one device to the Arduino and then from the Arduino to the other, and some device command bytes to make that happen of course.

1523  Using Arduino / Programming Questions / Re: Accelerometer (gy-521) to measure velocity and Force on: May 09, 2013, 01:04:11 pm
F=MA... force = mass x acceleration

You hit the ball with one mass to transfer momentum to the ball with a collision model, how elastic is a football? Not as much as a billiard ball and nowhere near as simple!

Good luck. Your teacher(s) only expect so much so blow their minds if you can.

1524  Using Arduino / Programming Questions / Re: Compile errors with Progmem on: May 09, 2013, 12:56:28 pm
Did/were you able to check that it didn't put the table in RAM?
I ask because I've never seen PROGMEM as the first thing on the line.
1525  Using Arduino / Programming Questions / Re: Compile errors with Progmem on: May 09, 2013, 11:13:07 am
Code:
static PROGMEM prog_uint32_t crc_table[16] = {

I wouldn't use static to declare a PROGMEM table. Static is for RAM.
Maybe
Code:
uint32_t PROGMEM table[16] = { etc etc etc


Using an old method, this worked with char arrays and still runs:

Code:
#include <avr/io.h>
#include <avr/pgmspace.h>

const char PROGMEM namesTable[] = { // all this text stored in flash
  "MARK\0FRANCIS\0JOHN\0ANDREW\0ROBERT\0SEAN\0HAYES\0LUDWIG\0HARRISON\0GRAND\0SALTER\0BOND\0"
};

PGM_P nT; // will point into namesTable

#define  FIRSTNAMES    6
#define  LASTNAMES     6
PGM_P    firstName[ FIRSTNAMES ];
PGM_P    lastName[ LASTNAMES ];

void  printProgstring( PGM_P FM )
{
  char fb;
  do
  {
    fb = pgm_read_byte( FM++ );   
    if ( fb )  Serial.print( fb );
  }
  while ( fb );
}

void setup(void)
{
  Serial.begin( 9600 );

  nT = namesTable;
  firstName[ 0 ] = nT;
 
  byte i; // only counting to 6 so 1 byte is enough
  for ( i = 1; i < FIRSTNAMES; i++ )
  {
    while ( pgm_read_byte( nT++ ));
    firstName[ i ] = nT++;   
  }
 
  for ( i = 0; i < LASTNAMES; i++ )
  {
    while ( pgm_read_byte( nT++ )); // find the \0 at the end of name[ i-1 ]
    lastName[ i ] = nT++;   
  }

  for ( i = 0; i < FIRSTNAMES; i++ )
  {
    printProgstring( firstName[ i ] );
    Serial.println( );   
  }
  Serial.println( );   
  for ( i = 0; i < LASTNAMES; i++ )
  {
    printProgstring( lastName[ i ] );
    Serial.println( );   
  }

}

void loop(void)
{
}
1526  Using Arduino / Programming Questions / Re: Serial monitor output to text file on: May 09, 2013, 10:55:04 am
Actually it was the trying to rt-click and get a menu. Ctrl-C does work but I never tried that till now.

And Serial Monitor does allow scrolling too. But Hyper Terminal allows saving incoming data to file and sending file data out. And what I can do with my own code goes beyond either.

1527  Using Arduino / Programming Questions / Re: PWM Water distiller on: May 09, 2013, 06:44:17 am
Quote
I suspect i have a 110v element labeled as a 240v.

Have you tried a step-down transformer?

1528  Using Arduino / Programming Questions / Re: Removing delay and averaging analog input help needed on: May 09, 2013, 06:32:44 am
Last time I played with using a led to control the brightness of the led, I started with this:

http://playground.arduino.cc//Learning/LEDSensor

and I ended up with slightly different code. It does flicker in low light.

Code:
//
// This example shows one way of using an LED as a light sensor.
// You will need to wire up your components as such:
//
//           + digital2
//           |
//           <
//           > 100 ohm resistor
//           <
//           |
//           |
//         -----
//          / \  LED, maybe a 5mm, clear plastic is good
//         -----
//           |
//           |
//           + digital3
//
// What we are going to do is apply a positive voltage at digital2 and
// a low voltage at digital3. This is backwards for the LED, current will
// not flow and light will not come out, but we will charge up the
// capacitance of the LED junction and the Arduino pin.
//
// Then we are going to disconnect the output drivers from digital2 and
// count how long it takes the stored charge to bleed off through the
// the LED. The brighter the light, the faster it will bleed away to
// digital3.
//
// Then just to be perverse we will display the brightness back on the
// same LED by turning it on for a millisecond. This happens more often
// with brighter lighting, so the LED is dim in a dim room and brighter
// in a bright room. Quite nice.
//
// (Though a nice idea, this implementation is flawed because the refresh
// rate gets too long in the dark and it flickers disturbingly.)


// just a few changes then....

#define LED_N_SIDE 7
#define LED_P_SIDE 6

unsigned long  now, mark, interval;
unsigned long checkUSecs = 2UL, ledOnTime = 100UL, senseMaxUSecs = 5000UL;

char  state = 0; // -128 <--> 127

void setup()
{
  //  now = micros();
}

void loop()
{
  static  unsigned int j = 0U;

  switch ( state )
  {
  case  0:
    {
      // Apply reverse voltage, charge up the pin and led capacitance
      pinMode(LED_N_SIDE,OUTPUT);
      pinMode(LED_P_SIDE,OUTPUT);
      digitalWrite(LED_N_SIDE,HIGH);
      digitalWrite(LED_P_SIDE,LOW);

      // Isolate the pin 2 end of the diode
      pinMode(LED_N_SIDE,INPUT);
      digitalWrite(LED_N_SIDE,LOW);  // turn off internal pull-up resistor

      now = mark = micros();
      state = 1;
      j = 0U;
      break;
    }

  case  1:
    {
//      if ( micros() != mark )
//      {
//        mark = micros();
        if ( digitalRead(LED_N_SIDE))
        {
          if (( micros() - now ) >= senseMaxUSecs )
          {
            state = 2; // quit reading
          }
        }
        else
        {
          state = 2;
        }
//      }
      break;
    }

  case  2:
    {
      // Turn the light on

      digitalWrite(LED_P_SIDE,HIGH);
      digitalWrite(LED_N_SIDE,LOW);
      pinMode(LED_P_SIDE,OUTPUT);
      pinMode(LED_N_SIDE,OUTPUT);
      mark = micros();
      state = 3;
      break;
    } 

  case  3:
    {
      // Turn the light off after ledOnTime microseconds
      if ( micros() - mark >= ledOnTime )
      {
        digitalWrite(LED_P_SIDE,LOW);
        //      delayMicroseconds(1000);
        // we could turn it off, but we know that is about to happen at the loop() start
        state = 0;
        break;
      }
    }
    break;
  }
}

1529  Using Arduino / Programming Questions / Re: PWM Water distiller on: May 09, 2013, 06:14:05 am
Hi Jason. I have a nice Black and Decker rice cooker (ran me $13 at Walmart) that shuts itself off when the water is steamed off. It does it either by weight or temperature rise but smaller or larger amount works the same.

Perhaps if you put a load sensor under the distiller and have it cut off during the last liter being distilled then you can avoid both the burn and the extra energy cost of distilling the last water that has the concentrated impurities from all the water you started with. After all, those impurities raise the boiling point so why not dump that water and start new?

Does your heater burn impurities to the bottom even when there's more than a little water in the pot or is that something you get after you let the thing boil dry or near dry?

1530  Using Arduino / Programming Questions / Re: Serial monitor output to text file on: May 09, 2013, 05:55:39 am
You can copy from the Serial monitor window easily enough.  No need to use yet another program.  Select what you want to copy using the mouse and Control/C will do the copy for you.

Running XP here and I was never able to do that which is why I tried Hyper Terminal for the first time in over 15 years.
Pages: 1 ... 100 101 [102] 103 104 ... 304