Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Simple Problem, Confusing Error... HELP! on: October 10, 2013, 10:30:12 am
#%$^#$%^$#^!!!!!

Thanks, I have done that before!
2  Using Arduino / Programming Questions / Simple Problem, Confusing Error... HELP! on: October 10, 2013, 10:25:39 am
So, the purpose of this code is to display a number by flashing a light...  ie, the number 213 would be displayed as:  flash-falsh...   flash...   flash-flash-flash.

This is designed to run as a loop, 20 cycles a second, turning the light on and off as needed.  This sketch will be integrated into a much larger project (a rocket flight computer, the light flashing tells you the highest altitude).

So, for what ever reason, the sketch is stuck on the first digit.  I ran diagnostics and found that while the "digit++" command at the bottom is occurring and increasing the value of "digit" by 1, "digit" goes back to a value of 1 when the loop restarts...  help?

FYI:  Instead of an LED flashing (I dont have one at the moment), it is transmitting something via Serial so the Serial light flashes...

Code:
//Example sketch for taking a 5 digit integer split it into digits and flash an LED to display them.
int integer = 32345;
int digit1;
int digit2;
int digit3;
int digit4;
int digit5;
int digit6;
int dig;
int digit;

int flashnum;
int fcount;
int count;
int dcount;
void setup()
{
 //find digits
digit1 = integer/10000;
digit2 = (integer-10000*digit1)/1000;
digit3 = (integer-10000*digit1-1000*digit2)/100;
digit4 = (integer-10000*digit1-1000*digit2-100*digit3)/10;
digit5 = integer-10000*digit1-1000*digit2-100*digit3-10*digit4;
Serial.begin(9600);
Serial.println(digit1);
Serial.println(digit2);
Serial.println(digit3);
Serial.println(digit4);
Serial.println(digit5);
}

void loop()
{
   
 
  delay(50);

  if (digit=1)
    {
      dig = digit1;
    }
  else if (digit=2)
    {
      dig = digit2;
    }
  else if (digit=3)
    {
      dig = digit3;
    }
  else if (digit=4)
    {
      dig = digit5;
    }
  else if (digit=5)
    {
      if (count<60)
        {
          count++;
          Serial.print("^^");
        }
      else
        {
       
        }
    }

  if (flashnum < dig)
      {
   
      if (fcount < 5)
        {
          Serial.print(flashnum);
          fcount++;
        }
      else if (fcount < 10)
        {
          fcount++;
        }
      else if (fcount = 10)
        {
          fcount=0;
          flashnum++;
        }
     }
    else
     {
       if (dcount < 30)
        {
          dcount++;
         
        }
       else
        {
          flashnum=0;
          if (digit=1)
          {
            digit=2;
          }
          else if (digit=2)
          {
            digit=3;
          }
          else if (digit=3)
          {
            digit=4;
          }
          else if (digit=4)
          {
            digit=5;
          }
          else if (digit=5)
          {
            digit=6;
          }
          else if (digit=6)
          {
            digit=7;
          }
          dcount=0;
         
         
        }
       
      }
 
   
}//end of loop
3  Using Arduino / Programming Questions / I2C Communication Error: expected primary-expression before ')' token on: September 02, 2013, 04:27:14 pm
So this code is orginally from here: https://forum.sparkfun.com/viewtopic.php?f=14&t=28900

Its purpose is to communicate with an accelerometer using the I2C setup.  And I have NO clue how to do that.  The code in the link was written for the Arduino UNO.  I modified it for the Arduino Mega 2650.  However at line:

Code:
int xVal = xL | (xH << );

I get the failure:
Quote
error: expected primary-expression before ')' token

Here is the modified code...  suggestions?

Code:
// 3-axis Accelerometer
// Sparkfun Electronics Triple Axis Accelerometer Breakout - LIS331
// Arduino Mega

/* Wiring:
    UNO LIS331

    3.3V VCC
    GND GND
    51 CS
    20 SDA/SDI
    50 SA0/SDO
    21 SCL/SPC
    */

#include <SPI.h>
#include <stdlib.h>
#include <stdio.h>

#define SS 51 // Serial Select -> CS on LIS331
#define MOSI 20 // MasterOutSlaveIn -> SDI
#define MISO 50 // MasterInSlaveOut -> SDO
#define SCK 21 // Serial Clock -> SPC on LIS331

#define SCALE 0.0007324; // approximate scale factor for full range (+/-24g)
// scale factor: +/-24g = 48G range. 2^16 bits. 48/65536 = 0.0007324

// global acceleration values
double xAcc, yAcc, zAcc;

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

  // Configure SPI
  SPI_SETUP();

  // Configure accelerometer
  Accelerometer_Setup();
}


void loop()
{
  readVal(); // get acc values and put into global variables

  Serial.print(xAcc, 1);
  Serial.print(",");
  Serial.print(yAcc, 1);
  Serial.print(",");
  Serial.println(zAcc, 1);

  delay(10);
}

// Read the accelerometer data and put values into global variables
void readVal()
{
  byte xAddressByteL = 0x28; // Low Byte of X value (the first data register)
  byte readBit = B10000000; // bit 0 (MSB) HIGH means read register
  byte incrementBit = B01000000; // bit 1 HIGH means keep incrementing registers
  // this allows us to keep reading the data registers by pushing an empty byte
  byte dataByte = xAddressByteL | readBit | incrementBit;
  byte b0 = 0x0; // an empty byte, to increment to subsequent registers

  digitalWrite(SS, LOW); // SS must be LOW to communicate
  delay(1);
  SPI.transfer(dataByte); // request a read, starting at X low byte
  byte xL = SPI.transfer(b0); // get the low byte of X data
  byte xH = SPI.transfer(b0); // get the high byte of X data
  byte yL = SPI.transfer(b0); // get the low byte of Y data
  byte yH = SPI.transfer(b0); // get the high byte of Y data
  byte zL = SPI.transfer(b0); // get the low byte of Z data
  byte zH = SPI.transfer(b0); // get the high byte of Z data
  delay(1);
  digitalWrite(SS, HIGH);

  // shift the high byte left 8 bits and merge the high and low
  int xVal = xL | (xH << );
  int yVal = yL | (yH << );
  int zVal = zL | (zH << );

  // scale the values into G's
  xAcc = xVal * SCALE;
  yAcc = yVal * SCALE;
  zAcc = zVal * SCALE;
}

void SPI_SETUP()
{
  pinMode(SS, OUTPUT);

  // wake up the SPI bus
  SPI.begin();

  // This device reads MSB first:
  SPI.setBitOrder(MSBFIRST);

  /*
  SPI.setDataMode()
  Mode    Clock Polarity (CPOL) Clock Phase (CPHA)
  SPI_MODE0    0    0
  SPI_MODE1    0    1
  SPI_MODE2    1    0
  SPI_MODE3    1    1
  */
  SPI.setDataMode(SPI_MODE0);

  /*
  SPI.setClockDivider()
  sets SPI clock to a fraction of the system clock
  Arduino UNO system clock = 16 MHz
  Mode SPI Clock
  SPI_CLOCK_DIV2 8 MHz
  SPI_CLOCK_DIV4 4 MHz
  SPI_CLOCK_DIV8 2 MHz
  SPI_CLOCK_DIV16 1 MHz
  SPI_CLOCK_DIV32 500 Hz
  SPI_CLOCK_DIV64 250 Hz
  SPI_CLOCK_DIV128 125 Hz
  */

  SPI.setClockDivider(SPI_CLOCK_DIV16); // SPI clock 1000Hz
}

void Accelerometer_Setup()
{
  // Set up the accelerometer
  // write to Control register 1: address 20h
  byte addressByte = 0x20;
  /* Bits:
  PM2 PM1 PM0 DR1 DR0 Zen Yen Xen
  PM2PM1PM0: Power mode (001 = Normal Mode)
  DR1DR0: Data rate (00=50Hz, 01=100Hz, 10=400Hz, 11=1000Hz)
  Zen, Yen, Xen: Z enable, Y enable, X enable
  */
  byte ctrlRegByte = 0x37; // 00111111 : normal mode, 1000Hz, xyz enabled

  // Send the data for Control Register 1
  digitalWrite(SS, LOW);
  delay(1);
  SPI.transfer(addressByte);
  SPI.transfer(ctrlRegByte);
  delay(1);
  digitalWrite(SS, HIGH);

  delay(100);

  // write to Control Register 2: address 21h
  addressByte = 0x21;
  // This register configures high pass filter
  ctrlRegByte = 0x00; // High pass filter off

  // Send the data for Control Register 2
  digitalWrite(SS, LOW);
  delay(1);
  SPI.transfer(addressByte);
  SPI.transfer(ctrlRegByte);
  delay(1);
  digitalWrite(SS, HIGH);

  delay(100);

  // Control Register 3 configures Interrupts
  // Since I'm not using Interrupts, I'll leave it alone

  // write to Control Register 4: address 23h
  addressByte = 0x23;
  /* Bits:
  BDU BLE FS1 FS0 STsign 0 ST SIM
  BDU: Block data update (0=continuous update)
  BLE: Big/little endian data (0=accel data LSB at LOW address)
  FS1FS0: Full-scale selection (00 = +/-6G, 01 = +/-12G, 11 = +/-24G)
  STsign: selft-test sign (default 0=plus)
  ST: self-test enable (default 0=disabled)
  SIM: SPI mode selection(default 0=4 wire interface, 1=3 wire interface)
  */
  ctrlRegByte = 0x30; // 00110000 : 24G (full scale)

  // Send the data for Control Register 4
  digitalWrite(SS, LOW);
  delay(1);
  SPI.transfer(addressByte);
  SPI.transfer(ctrlRegByte);
  delay(1);
  digitalWrite(SS, HIGH);
}
4  Using Arduino / Programming Questions / Truncating all decimals on: August 30, 2013, 03:00:10 pm
I want to turn a decimal number into an integer.

I have been using:

Code:
int num = decimal;

However, when I use a decimal like: 9.999, I get 10.  But I want 9.

Suggestions?
5  Using Arduino / Networking, Protocols, and Devices / Re: Xbee to Xbee Communication Issues on: January 02, 2013, 09:51:32 am
Paul,
Using two XBee Series 1 (802.15.4) with the 1mW antenna.  Shield is the Spark Fun sheild for Arduino (using it on a Uno).  Computer hookup is the Spark Fun USB Dongle.  I have checked the Xbees (I think), and believe them to be each on 9600.  Could you help me on checking the Xbees?  The X-CTU was a little confusing for me.

Thanks,
Ryan
6  Using Arduino / Networking, Protocols, and Devices / Re: Xbee to Xbee Communication Issues on: January 02, 2013, 09:17:10 am
Ahh, some how I knew that was coming  smiley-razz 

int loadcell;
int compRESPONSE;

void setup()
{
     Serial.begin(9600);
     Serial.println("12345");
     delay(1000);
     compRESPONSE = Serial.read();
     while (compRESPONSE < 0)
      {
          Serial.println("12345");
          delay(1000);
          compRESPONSE = Serial.read();
      }
}

void loop()
{
     loadcell = analogRead(0);
     Serial.println(loadcell);
     delay(25);
}
7  Using Arduino / Networking, Protocols, and Devices / Xbee to Xbee Communication Issues on: January 02, 2013, 01:05:36 am
Well, I think I am in a mess!  My program tells the Arduino board to send a numbered code to the computer 1 time per second.  When viewed on a serial monitor it should look like:

12345
12345
12345
12345
...

When the Arduino board receives any number in return it begins sending voltage signals from a load cell at 25 times per second. looking like this:

12345
12345
12345
100
100
101
100
100
101
100
100
102
99
...

However, when I hookup the Xbee units (using a USB dongle on the computer and the Xbee sheild on the board, I get this (on all baud rates):

1ag532
d7399
g
 
along with a few other symbols not of this world  smiley-lol  At some point, a communication seems to be sent, because it will start sending voltage data, but not on multiple lines, but on one long line...

Help? 
Please?

Thanks a bunch,
Ryan
8  Topics / Science and Measurement / Re: Help with Measuring Load Cell Voltage on: November 04, 2012, 07:40:27 am
It is an Aerocon Load Cell, used for Testing rocket motors with forces of up to 220lb.  And yes it does output in millivolts, my amplifier that I made hoever puts it up to 8.8v
9  Using Arduino / General Electronics / Measuring 5+v in Arduino Analog pins on: November 02, 2012, 10:11:09 pm
How could I measure more than 5v in the arduino?  I suppose it would be something along the lines of a resistor which would then need a conversion factor later...
10  Topics / Science and Measurement / Help with Measuring Load Cell Voltage on: November 02, 2012, 10:09:59 pm
Shouldnt be too hard, only problem is that the loadcells can out out up to 8.8v... too high for the Analog pins i think.  How can I turn the 8.8v into 5v?  Resistor?  I would prefer not to have to completely redesign the load cell setup to run on 5v smiley

Ryan
11  Using Arduino / Project Guidance / Re: Wireless Rocket Motor Testing on: October 29, 2012, 03:14:19 pm
Mark,
I would like to have the Arduino send voltage data as fast as possible, then have my software on the computer pick it up (30+ a sec).  Also what is the range, and is this a "transparent" radio?  Can it just be programmed as a serial port?  I like the Ciseco XRF and URF, but alas they are only sold in Europe smiley-sad
12  Using Arduino / Project Guidance / Wireless Rocket Motor Testing on: October 28, 2012, 06:43:23 pm
Should be fairly simple: PC Software wirelessly sends a firing command to an Arduino UNO via a wireless chip, Arduino trips a relay to ignite the motor (ignition requires a 12v car battery), load cell provides an analog voltage signal into Arduino, Arduino sends signal to PC via wireless chip, PC records voltage and converts it into thrust. 

Now, I am good with the software (doing this through VB.net and its SerialPort app)... the question is, which wireless method should I go through?  Wifly seems cheap but I cant find and programming help for the life of me.  Xbee seems confusing, which do I buy?  Will it extend 50-100m?  Can I still run the Xbee through VB.net using it as a serial port?  Im good with the Arduino board, and VB.net; new to wireless communications smiley

All help is appreciated, thanks a bunch!

Ryan
Pages: [1]