Loading...
  Show Posts
Pages: 1 [2] 3 4 ... 13
16  Using Arduino / Programming Questions / Re: Making a formula float free on: May 30, 2012, 09:35:19 am
say what?
17  Using Arduino / Programming Questions / Re: Making a formula float free on: May 30, 2012, 09:22:07 am
oh, formula = round (((2.330-0.003/2.000)-mm)/0.004) is equivalent to (4657-2*num)/8


I get it. no problem, I just work out a different formula above for each section of code.

except it's formula = round((((2330-(3/2))-2300)/4))

(2330 - 1.5) -2300

(2328.5 - 2300) / 4

28.5 / 4

Round(7.125)

7

100 - 7

Bin = 93


18  Using Arduino / Programming Questions / Re: Making a formula float free on: May 30, 2012, 09:13:00 am
jorgepl, different sections of the program have different constants based on what gear family you are testing (ok, so that kind of makes them variables, doesn't it? My bad). You are still using floats in that formula.

I've attached the complete sketch so you can see how it's being used. I'm trying to speed things up by eliminating float arithmatic, since I can put an int in, and get an int out.
19  Using Arduino / Programming Questions / Re: Making a formula float free on: May 30, 2012, 09:10:52 am
I'm confused. I use a spreadsheet to check my values before coding them.
20  Using Arduino / Programming Questions / Re: Making a formula float free on: May 30, 2012, 09:09:11 am
That's before the final / 1000

7.125=((((2330-(3/2))-2300)/4))



21  Using Arduino / Programming Questions / Re: Making a formula float free on: May 30, 2012, 08:55:05 am
jorgepl, those are constants.
22  Using Arduino / Programming Questions / Re: Making a formula float free on: May 30, 2012, 08:54:00 am
Majenko, the formula still comes out to 7.125

I need it to come out to 7125, then say

if formula >6999 & <7501
then formula = 7000
if formula >7500 & <8001
then formula = 8000

23  Using Arduino / Programming Questions / Re: GPS sketch Works on UNO not on Mega on: May 30, 2012, 08:32:17 am
On a 2560:

Serial0 is pins 0 (rx) & 1 (tx)
Serial1 is pins 18 (rx) & 19 (tx)
Serial2 is pins 16 (rx) & 17 (tx)
Serial3 is pins 14 (rx) & 15 (tx)

You refer to those ports as seen on page http://arduino.cc/en/Reference/Serial

You do not specify the pin numbers, the arduino already knows what pin number they are.
24  Using Arduino / Programming Questions / Making a formula float free on: May 30, 2012, 08:18:23 am
I have a formula that uses floats. I'd like to make it float free, and use ints only. Ideas?

The float version:

variables:

Where num = 2300, bin will return 93

Code:
// convert mm to bin numbers

int convert() {
float mm;
float maxmm = 2.330;
float range = .003;
float jump = .004;
int maxl = 100;

mm = (float)num/1000;

float formula = round((((maxmm-(range/2.000))-mm)/jump));

int f;

f = (int)formula;

int bin = maxl-f;

return bin;

}
25  Using Arduino / Displays / Re: Sending data from Arduino to uVGA-II in GFX (4DGL) Mode on: May 30, 2012, 06:46:31 am
Success! Thanks to 4DSysFan at http://4d.websitetoolbox.com/post/Converting-from-SGC-to-GFX-5858304, I now have an integer variable on the uVGA-II (result) that contains the same data as the integer variable on the Arduino (num). The print statements to the serial port had to be modified again, as the uVGA-II is looking for a $ as a start of packet, and a CR as the end of the packet:

  Serial3.print("$");
  Serial3.println(num, DEC);


Arduino sketch:

Code:
int req = 5; //mic REQ line goes to pin 5 through q1 (arduino high pulls request line low)
int dat = 2; //mic Data line goes to pin 2
int clk = 3; //mic Clock line goes to pin 3
int i = 0; int j = 0; int k = 0;
byte mydata[14];
int num;


void setup(){
  Serial3.begin(9600);
  Serial.begin(9600);
  pinMode(req, OUTPUT);
  pinMode(clk, INPUT);
  pinMode(dat, INPUT);
  digitalWrite(clk, HIGH); // enable internal pull ups
  digitalWrite(dat, HIGH); // enable internal pull ups
  digitalWrite(req,LOW); // set request at LOW
  
}

void loop(){
 
// get data from mic

  digitalWrite(req, HIGH); // generate set request

    for( i = 0; i < 13; i++ ) {

      k = 0;

      for (j = 0; j < 4; j++) {

      while( digitalRead(clk) == LOW) { } // hold until clock is high

      while( digitalRead(clk) == HIGH) { } // hold until clock is low

        bitWrite(k, j, (digitalRead(dat) & 0x1)); // read data bits, and reverse order )

      }

// extract data

      mydata[i] = k;

//      sign = mydata[4];

//      decimal = mydata[11];

//      units = mydata[12];


                

    }
    
// assemble measurement from bytes    

char buf[7];

for(int lp=0;lp<6;lp++)

  buf[lp]=mydata[lp+5]+'0';

buf[6]=0;

num=atol(buf); //assembled measurement, no decimal place added

 
  Serial3.print("$");
  Serial3.println(num, DEC);
  
  digitalWrite(req,LOW);

   //  delay(25);

}



uVGA-II 4DGL Code:

Code:
#platform "uVGA-II_GFX2"
// Micrometer GFX
#inherit "4DGL_16bitColours.fnc"
func main()
    var comvar;
    var result;
    gfx_Cls();
    txt_Set(FONT_SIZE, FONT2);
    gfx_Rectangle(75,75,150,120,WHITE);
    //print("Com test");
    //com_SetBaud(COM0,960);
    //to(COM0); print("serial input test:\n");
    repeat
        comvar := serin1();
        if(comvar == '$')
            //gfx_Cls();
            //print("$");
            result :=0;
        endif
        if(lookup8(comvar,"0123456789"))
           result:=(result*10)+(comvar-'0');
           //print("\n Char:",comvar);
        endif
        if(comvar ==13)
            txt_MoveCursor(12,10);
            print(result,"  ");
        endif
    forever
endfunc
26  Using Arduino / Displays / Re: Sending data from Arduino to uVGA-II in GFX (4DGL) Mode on: May 29, 2012, 04:21:00 pm
The speed problems were trying to build graphics on the arduino and output them serially to the uVGA. Now all the graphics are moved to the uVGA, and all I'm sending over to the uVGA is a 5 digit value, from variable num, in ascii. I can increase the speed later once I get it all working if necessary.

Serial3 is an output, not an input. I'm not doing any reads on the Arduino. I am trying to on the uVGA, on Serial1.

Serial.println(num); was just being used for debugging (serial monitor). I've // it out in the real version.


27  Using Arduino / Displays / Re: Sending data from Arduino to uVGA-II in GFX (4DGL) Mode on: May 29, 2012, 11:48:34 am
Would it help if during sending from the Arduino, I did a

Serial3.print(num, DEC);

instead of

Serial3.println(num);

I think I need to add a "separator" so the receiving unit knows where start and stop is.

Serial3.print(num, DEC);
Serial3.print("$");


Now I'm sending the ascii values 54 55 52 55 36 (6 7 4 7 $). On the other end, I need to read in until I hit $, and save to a variable.
28  Using Arduino / Displays / Sending data from Arduino to uVGA-II in GFX (4DGL) Mode on: May 29, 2012, 07:59:27 am
I'm migrating our micrometer project (http://www.instructables.com/id/Interfacing-a-Digital-Micrometer-to-a-Microcontrol/), which was working very well, from SGC mode (serial) to GFX mode (4DGL), due to speed issues. I've stripped out all the uVGA code that was being generated on the Arduino, so the Arduino simply collects data from the micrometer and sends it to the uVGA-II for further processing (serial 3 on the Arduino 2560 to serial 1 on the uVGA). The problem is actually a 4DGL issue, reading the data presented by the Arduino, and stuffing it into a variable. I can display the last character the Arduino sends, but not all 5 digits.

Anyone with 4DGL experience care to help out? (I'm sure I'll get "why don't you take this to 4D tech support". Did that already.) I'm stumped.

Arduino sketch attached, 4DGL test code below:

4DGL code reading the Arduino data from Serial 1:

Code:
#platform "uVGA-II_GFX2"
/*
     - serial interface test-
      -- PICASO Platform --
*/

#inherit "4DGL_16bitColours.fnc"

func main()
    var ch;
    gfx_Cls();
    txt_Set(FONT_SIZE, FONT2);
    gfx_Rectangle(75,75,140,120,WHITE);


    // now just stay in a loop
    repeat
        gfx_MoveTo(90,100);
        ch := serin1();

        if (ch != -1)
            print( [CHR] ch );   // if a key was received from PC, print its ascii value

        endif

    forever

endfunc
29  Using Arduino / Displays / Re: 4D uVGA-II SGC Issues on: May 23, 2012, 06:05:22 am
There were a couple of sticky issues converting my code to Arduino 1.0. Here are the areas that I found:

Serial3.print(byte(00)); //terminator
becomes
Serial3.write((uint8_t)0); //terminator

Serial3.print(byte(y)); //color
becomes
Serial3.write(y); //color

and

Serial3.print(int(z)); //data
stays the same

http://arduinotronics.blogspot.com
30  Using Arduino / Programming Questions / Re: amp | watt hour meter on: May 16, 2012, 01:07:07 pm
I just received the ACS714 bidirectional hall effect sensor from Pololu. I'll be modifying the project to watch ah in and ah out, with a peukert calculation, for estimated capacity remaining.

I'm adding a low voltage disconnect circuit with a hybrid relay (eliminates MOSFET heating and relay arcing) to protect the battery from excessive discharge. When sketch starts, the MOSFET is enabled, then the relay. Upon voltage drop below predermined value, the relay drops, then the MOSFET. Use a SSR for an AC Load. Full instructable at http://www.instructables.com/id/DIY-Amp-Hour-Meter-Arduino/.
Pages: 1 [2] 3 4 ... 13