Show Posts
Pages: [1] 2 3
1  Forum 2005-2010 (read only) / Interfacing / Re: Powershell serial communication with Arduino on: July 21, 2010, 06:37:25 pm
Thanks Zoomkat.  I would have used my usual way of doing things through cmd, vbscript in windows scripting host, but there are issues with calling the comm ocx.  Powershell uses the latest .NET objects so is very powerful once you get the hang of it.  I also recommend making sure you have version 2.0 of Powershell.  Anyway, because Powershell (which is now Microsoft's official scripting platform) uses .NET objects you have as much power as you would programming a C# application.  That's what got me through the hours of pulling my hair out with Powershell.  It is not like DOS or VBSCRIPT commands at all.  More like Ruby.  It did hurt my head.  
2  Forum 2005-2010 (read only) / Interfacing / Powershell serial communication with Arduino on: July 15, 2010, 04:13:13 pm
I was just pulling my hair out trying to figure out why I can't communicate with the Arduino through Windows Powershell (which relies on .NET components).  Hopefully this will help others.  The final code is:

Code:
$port = New-Object System.IO.Ports.SerialPort
$port.PortName = "COM6"
$port.BaudRate = "9600"
$port.Parity = "None"
$port.DataBits = 8
$port.StopBits = 1
$port.ReadTimeout = 9000 # 9 seconds
$port.DtrEnable = "true"

$port.open() #opens serial connection

Start-Sleep 2 # wait 2 seconds until Arduino is ready

$port.Write("93c") #writes your content to the serial connection

try
{
   while($myinput = $port.ReadLine())
   {
   $myinput
   }
}

catch [TimeoutException]
{
# Error handling code here
}

finally
{
# Any cleanup code goes here
}

$port.Close() #closes serial connection


The line that made all the difference was this:

$port.DtrEnable = "true"

Also, I have my Arduino write back a response after it executes every command, hence the read afterwards.

Hope this helps someone.
3  Forum 2005-2010 (read only) / Interfacing / Re: Melexis SMBus IR Thermometer - NFI on: February 15, 2010, 08:59:53 am
Thanks Sensorjunkie for taking the time to put this all in one place!  In the past few months I've learned a few things that might be helpful here.  

First, most Melexis Thermopiles for sale have a wide field of view, about 35-degrees.  There is a model F with a 10-degree field of view but seems difficult to get.  

For reference, a standard webcam has a field of view of 40-degrees by 30 degrees.   It's difficult to focus a thermopile because glass and plastic absorb around half of radiation between 3 and 20 micrometres.  Germanium is the best material, but any research will show you that those lenses are a fortune.  To get around the absorption issues in plastic you'll notice that the IR thermometer you buy from Sears uses a fresnal lens.  These lenses magnify with the least amount of lensing material.

Also, let me point out a common misconception I come across, the infrared that the Melexis picks up has almost NOTHING in common with the infrared that your digital camera can be converted to see.  Infrared photography deals with 800 to 1,000 nanometers, or just below the red spectrum.  If you measure that distance as a football field, thermal radiation starts about 10 football fields lower.  Silicon is basically transparent to that radition.  YOU CANNOT MODIFY YOUR DIGITAL CAMERA OR BUY A LOW COST SECURITY CAMERA that sees true thermal radiation from your PC power supply, let's say.  

In the January, 2010 issue of Nuts and Volts there is an interesting article by L. Paul Verhage, that uses a parallax thermopile for a near space infrared telescope.  The Melexis could be used in similar applications.  I think his technique for limited the field of view of the thermopile would work well with the Melexis.

Thanks again Sensorjunkie for making a go-to-place for getting the Melexis to work with Arduino!
4  Forum 2005-2010 (read only) / Interfacing / Re: Melexis SMBus IR Thermometer - NFI on: January 20, 2010, 09:37:18 am
Thanks Grumpy Mike, wrote that thing too fast.  I also failed to mention those are the resisters I used for the TPA, don't know if they'd work with the Melexis.  Also, while I'm here.  This is also a good thread on Sparkfun where I posted Dave Eaton's code.

http://forum.sparkfun.com/viewtopic.php?t=18771&start=0&postdays=0&postorder=asc&highlight=dave+eaton
5  Forum 2005-2010 (read only) / Interfacing / Re: Melexis SMBus IR Thermometer - NFI on: January 20, 2010, 09:14:29 am
Yes, this confused me at first too!  Pin 4 is data and pin 5 is the other one.

I2C: 4 (SDA) and 5 (SCL). Support I2C (TWI) communication using the Wire library.

I got it working very quickly with the TPA81, though I believe I had to add a (pull down) 1.4k transistor on each of those lines.

see: http://arduino.cc/en/Reference/Wire
6  Forum 2005-2010 (read only) / Interfacing / Re: Melexis SMBus IR Thermometer - NFI on: December 25, 2009, 02:54:43 pm
CalculusAE, I hope you're still getting emails for this thread.  I have been trying your code to get readings from the MLX90614 and haven't had any luck.  Now I don't know if I might have damaged the device or what.  I'm new to Arduino and as you know SMBus is not easy.  Anyway, I have the pin voltage in the Arduino's 3.3V, and SDA into Analog4 and SCL into Analog 5.  I have 4.7k pull-ups, but have also tried without.

It fires the init but doesn't get past the i2c_start_wait.  Any help GREALY appreciated!
7  Forum 2005-2010 (read only) / Interfacing / Re: GWS S125 Sail Winch Servo 360 Degrees Pan Sketch on: January 23, 2010, 12:49:04 pm
Thanks Mem!  I know I'm being difficult on the serial port requirement (P in front), but for those who don't have that I've integrated your code below.  Serial stuff aside, your handling of servo angles is superior, of course.  Thanks again!

Hopefully this will help anyone using Arduino to do camera/video panning.  Someday I hope to integrate it into CHDK for Canon cameras.  For those of you reading this post with similar interests, this servo is easy to use and can be plugged straight into an Arduino board, as the photo shows.  

The servo comes with a winch attachment, not standard servo wheels (one of which is attached in photo).  So if you get this servo make sure you also have/get servo wheels to attach your platform.

Code:
#include <Servo.h>
#include <SoftwareSerial.h>

Servo panServo;

// SERVO VARS
int angle = 0;
const int pulse0Degrees = 1000;   // pulse width for 0 degrees
const int pulse360Degrees = 1940;  // pulse width for 360 degrees
const int pcenter = 1000; // using 1000 for center, or 0 degrees, you may want to use something different

int servoPanPin = 9;     // Control pin for servo motor

void setup() {
  Serial.begin(9600);         // connect to the serial port
  panServo.attach(servoPanPin);  
 
 // Default center, or close to it
 panServo.writeMicroseconds(pcenter);      // close to center GWS125-IT/2BB/F ?
}

void loop() {
    readSerialString();  // read, wait for command
}

void readSerialString () {
 if ( Serial.available())
  {
    char ch = Serial.read();
    if(ch >= '0' && ch <= '9')              // is ch a number?  
      angle = angle * 10 + ch - '0';           // yes, accumulate the value
    else if(ch == 'P'| ch == 'p')  
    {
      int pulse = map(angle,0,360,pulse0Degrees, pulse360Degrees);
      panServo.writeMicroseconds(pulse);
      angle = 0;
    }
  }
}


Servo attached to Arduino Nano

8  Forum 2005-2010 (read only) / Interfacing / GWS S125 Sail Winch Servo 360 Degrees Pan Sketch on: January 22, 2010, 08:09:40 pm
From http://www.acroname.com/, I bought a GWS S125 Sail Winch Servo 1T for panning.  I want to pan 360 degrees; rather, I want to set it to any degree I want.  But I couldn't find a sketch that would do that.  So I wrote my own.  I found I had to add 24 milliseconds to get 90, 180 and 270 degrees correctly.  Hopefully, the Arduino Gods will have a fix, or other improvements.

To use this sketch, put your servo on pin 9 and load the serial window.  Type p90 for 90 degrees, or p1 for 1 degree, or p275 for 275 degrees.  You get the idea.

Code:

#include <Servo.h>
#include <SoftwareSerial.h>

Servo panServo;

// SERIAL PORT VARS
char cString[50];  // array that will hold command string
int iBufferIndex = 0; // index of buffer characters rec'd
int iBuffer = 0;

// SERVO VARS
int icount = 0;
long pval = 0; // pan val to send to servo
float pvalfloat = 0;
int pcenter = 1000; // using 1000 for center, or 0 degrees, you may want to use something different
float degrees360inms = 940; // 360 Degrees in servo milliseconds. Again you might find something different
float degreeinms = (degrees360inms/(float)360); // 1 Degree in Milliseconds.
float msadjust = 24; // millisecond (NOT degrees) adjustment, added to above.  Kludgey, which I knew a better solution

int servoPanPin = 9;     // Control pin for servo motor

void setup() {
  Serial.begin(9600);         // connect to the serial port
  panServo.attach(servoPanPin);  
 
 // Default center, or close to it
 panServo.writeMicroseconds(pcenter);      // close to center GWS125-IT/2BB/F ?
}

void loop() {
    readSerialString();  // read, wait for command
    processSerialString(); // process command, either pan or tilt
}

void readSerialString () {
     while (Serial.available ())
     {
     iBuffer = Serial.read();

     cString[iBufferIndex]  = iBuffer;
     iBufferIndex++;
     cString[iBufferIndex]= '\0';
     delay(10);  //never learned why this is necessary, but won't work without it
     }
    
}
 
void processSerialString() {
   if( iBufferIndex > 0) {
  
      // PAN
      if(cString[0] == 'P' | cString[0] == 'p') // first char should be P or T
      {
        cString[0] = ' ';
        pval = atoi(cString); // pan value is number after P, in degrees
        pvalfloat = (float)pval; // we neet float because degrees to milliseconds calc produces fractions

        if(pvalfloat==0) // we're at center so don't throw off with adjustment
        {
        pvalfloat = (pvalfloat * degreeinms); // degrees times 940/360
        }
        else
        {
        pvalfloat = (pvalfloat * degreeinms) + msadjust; // 940 milliseconds * (940 ms / 360) + ms adjustment, like 24
        }
        
        pvalfloat = pvalfloat + pcenter; // now add those degress in milliseconds to center 1000
  
      //   Serial.println();
         Serial.print("P in degrees: ");
         Serial.print(pval, DEC);
         Serial.print(" P in milliseconds: ");
         Serial.println(pvalfloat, DEC);
 
//      panServo.write(pval);      
      panServo.writeMicroseconds(pvalfloat);
      }
  
      
      // Re-init buffer stuff
      iBufferIndex = 0;
      iBuffer = 0;
      icount = 0;
      pval = 0;
      pvalfloat = 0;
      
   } // if string isn't 0

}

9  Forum 2005-2010 (read only) / Interfacing / Re: MLX90614 Infrared Sensor data capture on: December 24, 2009, 11:38:42 am
Hi, I found another thread on this forum, from 2008, that will supposedly work with this device http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1214872633

I followed his instructions (though didn't know what to make of changing the cpp file so left it alone).  Unfortunately, he doesn't explain hooking up the device to the board.

From posts about 2-wire I assume that pin 0 should be SCL, so I put that on pin 1 of my device, and pin 1 on the Arduino should be SDA, so I put that on pin 2 of my device.  I then clumsly stepped down the voltage from the Arduino (though a LED and transistor) to around 3 volts and put that on the VDD pin, and put VSS into Arduino ground.

It doesn't get any readings.  Does the wiring seem okay to you?  THANK!!!!
10  Forum 2005-2010 (read only) / Interfacing / Re: MLX90614 Infrared Sensor data capture on: December 24, 2009, 09:45:40 am
Hi Thanks.  I sense there are 2 schools of thoughts 2-wire communications in Arduino, no pun intended smiley-wink.  Those that say you have to go straight to hardware, like this example, and those that use a 2-wire library.  For learning, I'm going to try 2-wire first, but anyone's thoughts on this would be appreciated.

Also, this device is 3 volt.  I read that Arduino has built-in pull up resistors.  Do I need resistors between it and the Arduino?
11  Forum 2005-2010 (read only) / Interfacing / MLX90614 Infrared Sensor data capture on: December 23, 2009, 09:15:48 pm
I have a Melix MLX 90614 Infrared Thermometer.  The datasheet is here http://www.melexis.com/Assets/IR_sensor_thermometer_MLX90614_Datasheet_5152.aspx

I also found some code (below), from Sparkfun comments, that is supposed to pull data off the sensor.  But it doesn't explain setup.  

By looking at various other posts and stuff on Internet I hooked up the ground (device Pin 4) to Analog 2 and Power (device Pin 3) to Analog 3.  I then attached Pin 2 of the device (PWM/SDA) to Digital 4 and Pin 1 of the device (SCL/Vz) to Digital 5.

I then run the code.  It transmits "Start Read" That it doesn't give back a temperature doesn't surprise me, so out of my depth am I.  But it doesn't even return any printlns in the i2c_read_temperature_f() function.  Is there a reason that function never executes to that point?

Code:
#include <Wire.h>

static void nunchuck_setpowerpins()
{
#define pwrpin PORTC3 // or Analog 3
#define gndpin PORTC2 // or Analog 2
DDRC |= _BV(pwrpin) | _BV(gndpin);  //DDRC - The Port C Data Direction Register - read/write
PORTC &=~ _BV(gndpin); //PORTC - The Port C Data Register - read/write
PORTC |= _BV(pwrpin);
delay(100); // wait for things to stabilize
}

void i2c_start() {
TWCR = (1 << TWINT) | (1 << TWSTA) | (1 << TWEN); // send start condition
while (!(TWCR & (1 << TWINT)));
}

void i2c_write_byte(char byte) {
TWDR = byte;
TWCR = (1 << TWINT) | (1 << TWEN); // start address transmission
while (!(TWCR & (1 << TWINT)));
}

char i2c_read_byte() {
TWCR = (1 << TWINT) | (1 << TWEA) | (1 << TWEN); // start data reception, transmit ACK
while (!(TWCR & (1 << TWINT)));
return TWDR;
}

void i2c_receive_pec() {
TWCR = (1 << TWINT) | (1 << TWEN); // start PEC reception, transmit NACK
while (!(TWCR & (1 << TWINT)));
}

void i2c_stop() {
TWCR = (1 << TWINT) | (1 << TWSTO) | (1 << TWEN); // send stop condition
}

//Returns 100 times the temperature read by the sensor giving a 0.01 degree resolution.
long i2c_read_temperature_f() {long low_byte, high_byte;

// DDRC = 0; // all inputs
// PORTC = (1 << PORTC4) | (1 << PORTC5); // enable pull-ups on SDA and SCL, respectively

TWSR = 0; // clear bit-rate prescale bits
TWBR = 192; // produces an SCL frequency of 50 kHz with a 20 MHz CPU clock speed.

i2c_start();
// The expected value of TWSR & 0xF8 is now 0x08 (Start condition transmitted).

i2c_write_byte(0);// 0 is the universal write address for slaves.
// The expected value of TWSR & 0xF8 is now 0x18 (SLA+W transmitted ACK received).

i2c_write_byte(0x07); // read TObj1 (0x07) from RAM
// The expected value of TWSR & 0xF8 is now 0x28 (Data transmitted ACK received).

i2c_start();
// The expected value of TWSR & 0xF8 is now 0x10 (Repeated start has been transmitted).

i2c_write_byte(1); // 1 is the universal read address for slaves.
// The expected value of TWSR & 0xF8 is now 0x40 (SLA+R transmitted ACK received).

low_byte = i2c_read_byte();
// The expected value of TWSR & 0xF8 is now 0x50 (Data received ACK received).

high_byte = i2c_read_byte();
// The expected value of TWSR & 0xF8 is now 0x50 (Data received ACK received).

i2c_receive_pec(); // read packet error code (PEC)
// The expected value of TWSR & 0xF8 is now 0x58 (Data received NOT ACK received).

i2c_stop();

// Tk is temperature in Kelvin, Tf is temperature in degrees Fahrenheit, To is the raw
// value of the object temperature as returned by the sensor
// 100 Tk = To × 2 (from the datasheet section 8.7.2--To has the units 0.02K)
// Tf = Tk × 9/5 - 459.67 (conversion from Kelvin to Farenheit)

// 100 × Tf = 100 × Tk × 9/5 - 45967
// 100 × Tf = To × 2 × 9/5 - 45967
// 100 × Tf = To × 18/5 - 45967

 long total = 256*high_byte+low_byte;
 Serial.print("final: ");
 Serial.println(total,DEC);

return (256*high_byte+low_byte) * 18/5 - 45967; // return temperature in units of 0.01°F
}

void setup()
{
Serial.begin(57600);
nunchuck_setpowerpins();

}

void loop()
{
Serial.println("Start Read");

long object_temperature_f = 0;
object_temperature_f = i2c_read_temperature_f();

Serial.println(object_temperature_f,DEC);
delay(1000);

}

12  Forum 2005-2010 (read only) / Exhibition / Re: [Average Difficulty]Mouse-Controlled Laser-Turret on: December 19, 2009, 11:09:56 pm
I think a lot about pan/tilt devices and your CD case idea is very good!  I haven't seen that before.   It's unfortunate that some people were overly critical, but I think they're just frustrated by the photo which makes it difficult to appreciate your work.  But the perfect is the enemy of the good and what you posted is better than nothing for anyone interested in pan/tilts and lasers.  Good work!  And THANK YOU for taking the time to share it.
13  Forum 2005-2010 (read only) / Exhibition / Re: Arduino Robotic Panorama Head on: September 30, 2010, 02:07:57 pm
I'm using Microsoft Image Composition Editor (ICE).  It's free and here

http://research.microsoft.com/en-us/um/redmond/groups/ivm/ICE/

I agree, the sky would be nice, and the ground, but I haven't gotten there yet.  
14  Forum 2005-2010 (read only) / Exhibition / Arduino Robotic Panorama Head on: September 30, 2010, 08:08:56 am
Robot that takes a 360-degree series of pictures.  After, stitching software compiles them into a panorama.  I host them at http://www.photosynth.net/userprofilepage.aspx?user=maxrottersman

Arduino robot construction details at:

http://maxotics.blogspot.com/2010/09/diy-robotic-panorama-head.html

I send serial commands to the Arduino through a PC.  I also have a version that runs completely off the Arduino; I use a switch to start/stop the pan/tilting.

I use Powershell to both send commands to the Arduino, and to capture/download images from the digital camera.

Hopefully what I've learned will help others.  

Max
15  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Serial text command to pan tilt servos on: June 13, 2010, 06:02:06 pm
I haven't worked with this stuff in a while.  I do know that I gave up on getting it to work with the command letter in front, like P100.  So the way to do it is, for example, 1100S.  But my code uses degrees and inputs and figures out those numbers.  So I'd never send something like P2100, it might be 110P, for 110 degrees to Pan servo.

I can't tell from your code what is wrong, but this is my latest code and it has worked very well.  (you can see the application for it at http://www.thitle.com  There is a bunch of code that reads from a TPA81 Thermopile array which you can ignore.  Sorry I can't be more help at the moment.  

Hopefully something here will click with you.  Also, I'd first try to get it working from the serial window of a PC.  9600 works fine.  I'd use that.  Keep in mind that you can get into timing problems with the Arduino if you deviate from norms.

Code:
#include <Servo.h>
#include <Wire.h>
#include <SoftwareSerial.h>

Servo panServo;
Servo tiltServo;

// TPA81
#define rxPin 2                                        // Pin for rx
#define txPin 3                                        // Pin for tx
#define address 0x68                                   // Address of TPA81
#define softReg 0x00                                   // Byte for software version
#define ambiant 0x01                                   // Byte for ambiant temperature
int temperature[] = {0,0,0,0,0,0,0,0};                 // Array to hold temperature data

float angle = 0; // changed to float for fractional degree rotation
boolean isFraction = false;

// *** PAN SERVO ***
// SERVO VARS 360 degrees GWServo S125 1T/2BB
//const int panMin = 1000;   // pulse width for 0 degrees
//const int panMax = 1940;  // pulse width for 360 degrees
//const int pcenter = 1000; // using 1000 for center, or 0 degrees, you may want to use something different

// SERVO VARS 180 degrees HITEC HS-311
const int panMin = 900;   // pulse width for 0 degrees
const int panMax = 2350;  // pulse width for 360 degrees
const int pcenter = 1500; // using 1000 for center, or 0 degrees, you may want to use something different

// *** TILT SERVO
const int tiltMin = 900;
const int tiltMax = 2350;

int servoPanPin = 9;     // Control pin for servo motor
int servoTiltPin = 10;     // Control pin for servo motor

// Can use this later for moving servo more slowly on big jumps
//int servoPanSavePos = 0;
//int servoTiltSavePos = 0;

void setup() {
  Serial.begin(9600);         // connect to the serial port
  panServo.attach(servoPanPin, panMin, panMax);  
  tiltServo.attach(servoTiltPin, tiltMin, tiltMax);  

// Center PAN
int pulsecenter = map(90,0,180,panMin, panMax); // 180 Servo
panServo.writeMicroseconds(pulsecenter);
// Center TILT
pulsecenter = map(45,0,180,tiltMin, tiltMax); // 180 Servo
tiltServo.writeMicroseconds(pulsecenter);
 
//INIT TPA81
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);

Wire.begin();
//delay(100);                                          // Wait to make sure everything is powerd up
  
//int software = getData(softReg);                     // Get software version
//Serial.print("TPA81 Example  V:");
//Serial.println(software);                              // Print software version to the screen

}

void loop() {
    readSerialString();  // read, wait for command
}

void readSerialString () {
 if ( Serial.available())
  {
    char ch = Serial.read();
    
    if(ch >= '0' && ch <= '9')              // is ch a number?  
      {
      // we're in integer part of number
      if (isFraction == false)
      {
      angle = angle * 10 + ch - '0';           // yes, accumulate the value
      }
        // were in fraction, add it
        else
        {
        angle = angle + float((ch - '0') * 0.1);
        }
    }
    else if(ch == '.')
    {
    isFraction = true; // next number will be fractional
    }
    else if(ch == 'P'| ch == 'p')  
    {
     int pulse = mapFloat(angle,0,180,panMin, panMax); // 360
     panServo.writeMicroseconds(pulse); //
         Serial.print("P");
         //Serial.println(angle, DEC);
        printDouble((double)angle, 1);
        angle = 0;
        isFraction = false;
    }
    else if(ch == 'T'| ch == 't')  
    {
      int pulseTilt = mapFloat(angle,0,180,tiltMin, tiltMax);
      tiltServo.writeMicroseconds(pulseTilt); //
//      tiltServo.write(angle); old, simple way
      Serial.print("T");
      printDouble((double)angle, 1);
//      Serial.println(angle, DEC);
      angle = 0;
      isFraction = false;
    }
    else if(ch == 'R'| ch == 'r')  
    {
      //Serial.println("Reading temp...");
      for(int i = 0; i < 8; i++)
        { // Loops and stores temperature data in array
        temperature[i] = getData(i+2);
        }
        // This order, sensor horizontal, positioned to left of card
        Serial.print(temperature[7]);
        Serial.print(" ");    
        Serial.print(temperature[6]);
        Serial.print(" ");    
        Serial.print(temperature[5]);
        Serial.print(" ");    
        Serial.print(temperature[4]);
        Serial.print(" ");    
        Serial.print(temperature[3]);
        Serial.print(" ");    
        Serial.print(temperature[2]);
        Serial.print(" ");    
        Serial.print(temperature[1]);
        Serial.print(" ");    
        Serial.print(temperature[0]);
        Serial.println(" ");    
    }
  }
}


int getData(int reg){                                  // Function to receive one byte of data from TPA81
  Wire.beginTransmission(address);                     // Begin communication with TPA81
  Wire.send(reg);                                      // Send reg to TPA81
  Wire.endTransmission();
  Wire.requestFrom(address, 1);                        // Request 1 byte
  while(Wire.available() < 1);                         // Wait for byte to arrive
  int data = Wire.receive();                           // Get byte
  return(data);                                        // return byte
}

// Need this to send servor degrees with fractions, like 10.5 degrees
// Thanks  Cees-Willem
float mapFloat(float x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

void printDouble( double val, byte precision){
  // prints val with number of decimal places determine by precision
  // precision is a number from 0 to 6 indicating the desired decimial places
  // example: lcdPrintDouble( 3.1415, 2); // prints 3.14 (two decimal places)

  if(val < 0.0){
    Serial.print('-');
    val = -val;
  }

  Serial.print (int(val));  //prints the int part
  if( precision > 0) {
    Serial.print("."); // print the decimal point
    unsigned long frac;
    unsigned long mult = 1;
    byte padding = precision -1;
    while(precision--)
  mult *=10;

    if(val >= 0)
 frac = (val - int(val)) * mult;
    else
 frac = (int(val)- val ) * mult;
    unsigned long frac1 = frac;
    while( frac1 /= 10 )
 padding--;
    while(  padding--)
 Serial.print("0");
    Serial.println(frac,DEC) ;
  }
}


Pages: [1] 2 3