Page 2 of 3

Re: Datalogging 10 bit stream

Posted: Sat Oct 13, 2012 11:29 am
by Matt
Nistune runs under linux but there is a problem with the comms dropping out with consult which I have on my list to look at

I'm trying to get VEMS working at the moment and get that release done. Then I'll add this one next, but we need a clear definition of inputs to use

Re: Datalogging 10 bit stream

Posted: Tue Oct 23, 2012 10:18 pm
by Matt
Okay guys here is your Anduino solution. There are no Nistune software changes required for this so it will work with all current Nistune version. Basically I've taken the DLP definitions and protocol and put most of it into the Arduino. Several hours later we have something which is compatible with the analog inputs for DLP Design A/D converter and means no additional Nistune code needed :D

Get the code below, compile and upload to your chosen Arduino device. It creates a COM port @ 115200bps and acts like a DLP device for the purpose of Nistune uses. Nistune will poll the device, then setup binary mode and then query channels 1-8. I've tested tonight with two channels. Make sure the device is grounded. I seem to get a bit of fluctuation on my bench but that may be the power supply I'm using

Channel 1 (A0) is AFR LHS like with DLP and channels 2-6 (A1-A5) are auxillary inputs AUX1-AUX5

Code: Select all

/* Arduino One - DLP emulation */

const int DLP_CMD_DIGITAL_IN_CH1 = 0x41;
const int DLP_CMD_DIGITAL_IN_CH2 = 0x53;    
const int DLP_CMD_DIGITAL_IN_CH3 = 0x44;    
const int DLP_CMD_DIGITAL_IN_CH4 = 0x46;    
const int DLP_CMD_DIGITAL_IN_CH5 = 0x47;    
const int DLP_CMD_DIGITAL_IN_CH6 = 0x4E;    
const int DLP_CMD_DIGITAL_IN_CH7 = 0x4A;    
const int DLP_CMD_DIGITAL_IN_CH8 = 0x4B;

const int DLP_CMD_ANALOG_IN_CH1 = 0x5A;
const int DLP_CMD_ANALOG_IN_CH2 = 0x58;
const int DLP_CMD_ANALOG_IN_CH3 = 0x43;
const int DLP_CMD_ANALOG_IN_CH4 = 0x56;
const int DLP_CMD_ANALOG_IN_CH5 = 0x42;
const int DLP_CMD_ANALOG_IN_CH6 = 0x4E;
const int DLP_CMD_ANALOG_IN_CH7 = 0x4D;
const int DLP_CMD_ANALOG_IN_CH8 = 0x2C;

const int DLP_CMD_TEMPERATURE_IN_CH1 = 0x39;
const int DLP_CMD_TEMPERATURE_IN_CH2 = 0x30;
const int DLP_CMD_TEMPERATURE_IN_CH3 = 0x2D;
const int DLP_CMD_TEMPERATURE_IN_CH4 = 0x3D;
const int DLP_CMD_TEMPERATURE_IN_CH5 = 0x4F;
const int DLP_CMD_TEMPERATURE_IN_CH6 = 0x50;
const int DLP_CMD_TEMPERATURE_IN_CH7 = 0x5B;
const int DLP_CMD_TEMPERATURE_IN_CH8 = 0x5D;

const int DLP_SETUP_FARENHEIT = 0x4C; // not used
const int DLP_SETUP_CELCIUS = 0x3B; // not used
const int DLP_SETUP_ASCII = 0x60;
const int DLP_SETUP_BINARY = 0x5C;

const int DLP_CMD_PING = 0x27;
const int DLP_RESP_PING = 0x51;

const int SET_MODE_ASCII = 0;
const int SET_MODE_BINARY = 1;

const float AD_MULTIPLIER = 5.0/1024.0;

void setup() {
  Serial.begin(115200);
  pinMode(A0,INPUT);
  pinMode(A1,INPUT);
  pinMode(A2,INPUT);
  pinMode(A3,INPUT);
  pinMode(A4,INPUT);
  pinMode(A5,INPUT);
}

int rxByte = 0;
int currMode = SET_MODE_ASCII;
int sensorValue = 0;

void loop() 
{
  if (Serial.available() > 0)
  {
     rxByte = Serial.read();
     int sendADVal = false;
     int sendTempVal = false;
     
     switch (rxByte)
     {
       case DLP_SETUP_ASCII:
         currMode = SET_MODE_ASCII;
         break;
       case DLP_SETUP_BINARY:
         currMode = SET_MODE_BINARY;
         break;
       case DLP_SETUP_FARENHEIT:
         break; // not used
       case DLP_SETUP_CELCIUS:
         break; // not used
       case DLP_CMD_PING:
         // ping response
         Serial.write(DLP_RESP_PING);
         break;
       case DLP_CMD_ANALOG_IN_CH1:
         sensorValue = analogRead(A0);
         sendADVal = true;
         break;
       case DLP_CMD_ANALOG_IN_CH2:
         sensorValue = analogRead(A1);
         sendADVal = true;
         break;
       case DLP_CMD_ANALOG_IN_CH3:
         sensorValue = analogRead(A2);
         sendADVal = true;
         break;
       case DLP_CMD_ANALOG_IN_CH4:
         sensorValue = analogRead(A3);
         sendADVal = true;
         break;
       case DLP_CMD_ANALOG_IN_CH5:
         sensorValue = analogRead(A4);
         sendADVal = true;
         break;
       case DLP_CMD_ANALOG_IN_CH6:
         sensorValue = analogRead(A5);
         sendADVal = true;
         break;
       case DLP_CMD_ANALOG_IN_CH7:
       case DLP_CMD_ANALOG_IN_CH8:
         sensorValue = 0; // not available
         sendADVal = true;
         break;
       case DLP_CMD_TEMPERATURE_IN_CH1:
       case DLP_CMD_TEMPERATURE_IN_CH2:
       case DLP_CMD_TEMPERATURE_IN_CH3:
       case DLP_CMD_TEMPERATURE_IN_CH4:       
       case DLP_CMD_TEMPERATURE_IN_CH5:       
       case DLP_CMD_TEMPERATURE_IN_CH6:       
       case DLP_CMD_TEMPERATURE_IN_CH7:       
       case DLP_CMD_TEMPERATURE_IN_CH8:       
         sensorValue = 0; // not available
         sendTempVal = true;       
         break;       
       default:
         break;
     }
     
     if (sendADVal || sendTempVal)
     {
        if (currMode == SET_MODE_BINARY)
        {
           Serial.write((char)(sensorValue >> 8));
           Serial.write((char)(sensorValue));
        }
        else
        {
           Serial.print((float)sensorValue * AD_MULTIPLIER,2);
           Serial.println("V");
        }
     }
  }
}

Re: Datalogging 10 bit stream

Posted: Tue Oct 23, 2012 10:24 pm
by Matt
Okay followup post. The indenting gets lost when posting on the forum, so I've included a zip file here to use instead

Okay as for reasons for this way:
1. MIL-tec solution with configuring AD outputs to power the boost sensor straight from the board plugged in is fine but you waste inputs.

You can still modify my code and just assign unused extra channels with 0 response, the same as 7 and 8 which have no physical inputs.

2. Alternate protocol format. We dont use the header because definitions are in the AUX1.csv files etc. Also prefer binary over text as its easier to parse and my DLP code already does it for free
Sensor1 name, Sensor2 name,Sensor3 name<CR><LF>
value1, value2, value3<CR><LF>

Re: Datalogging 10 bit stream

Posted: Wed Oct 24, 2012 12:07 am
by djstatic
Matt wrote:Okay followup post. The indenting gets lost when posting on the forum, so I've included a zip file here to use instead
Then use the "code" tag :wink: Exhibit A:

*matt edit*
Thanks. Fixed! Now I look like a dumb ass 8)

Its right there next to "quote" !!

Re: Datalogging 10 bit stream

Posted: Mon Jan 21, 2013 11:06 am
by makro86
Hi Matt,

I'm trying to understand all of the code in the sketch.

Code: Select all

if (sendADVal || sendTempVal)
     {
        if (currMode == SET_MODE_BINARY)
        {
           Serial.write((char)(sensorValue >> 8));
           Serial.write((char)(sensorValue));
        }
        else
        {
           Serial.print((float)sensorValue * AD_MULTIPLIER,2);
           Serial.println("V");
        }
     }
(char)(sensorValue >> 8)
What is the purpose of this? Why would you bit shift the value 8 places across?

Re: Datalogging 10 bit stream

Posted: Mon Jan 21, 2013 10:38 pm
by Matt
To put out the MSB of the value first, and then the LSB

(char) conversion filters to 8 bits. Doing the shift before (char) enables us to put the MSB out

Re: Datalogging 10 bit stream

Posted: Wed Jan 29, 2014 3:22 am
by dlP
Hey Matt, i have an unused board with a pic18 in it, and i'm trying to emulate the DLP IO8 serial protocol.
But i'm getting an Comm. TimeOut at the wideband window in NISTUNE. See pics attached please...

Can you tell me wich mode are NISTUNE using (ASCII or binary).
And if it is ASCII, is there a null character or CR at the end of every response?


Thanks!

Re: Datalogging 10 bit stream

Posted: Wed Jan 29, 2014 9:50 pm
by Matt
Configured for Binary mode (and Celcius)

We ping with 0x27

Then we send a command to read inputs Analog IN CH 1.. CH7

Afterwards we expect 14 bytes back (2 bytes per each channel)

There are no CR/LF characters

Your output 0x27 (ping) then 0x5A (CH1) then 0x58 (CH2) then 0x58 (CH2 again?!) then 0x43 (CH3) is reading the channels

Response 0x51 is correct, then 2 x bytes for each channel. Appears too many bytes below

Re: Datalogging 10 bit stream

Posted: Fri Jan 31, 2014 7:57 am
by dlP
Thanks Matt!

The first time you query DLP also set C° and Binary mode, so the complete secuence is...

27 '
3B 5C 5A 58 43 56 42 4E 4D ;\ZXCVBNM

and then repeatedly...

27 '
5A 58 43 56 42 4E 4D ZXCVBNM


All AUX sorted out, but... how are you interpreting/scalling first channel (AFR) bytes? may be 0v:8-5v:32, linearly? can i change this scalling in nistune?

Edit: got it... afr1.csv ... :oops:

Re: Datalogging 10 bit stream

Posted: Fri Jan 31, 2014 12:39 pm
by dlP

Re: Datalogging 10 bit stream

Posted: Mon Feb 03, 2014 8:09 pm
by Matt
Ahah... pretty clever!

Re: Datalogging 10 bit stream

Posted: Tue Dec 30, 2014 7:02 pm
by Tengis
Found this through a google search. I've been getting into programming and recently purchased an arduino for other purposes. I may have to try this out.

Re: Datalogging 10 bit stream

Posted: Sun Sep 10, 2017 10:14 pm
by vanepico
Hi guys,

I don't know if this will help anyone, but if you are using an Arduino DLP you can alter the "pinmode(A*, INPUT)" to "pinmode(A*, INPUT_PULLUP)" you will get less fluctuation if there is no signal connected.

I am still having some problems with my AFR readout being up to 0.7 out however.

Re: Datalogging 10 bit stream

Posted: Mon Sep 11, 2017 4:02 pm
by Matt
Not sure on the variance reported, but sounds like PULLUP uses an internal low value resistor for the line. DLPs can have flucutation on the pins if unused lines are not all pulled low

Re: Datalogging 10 bit stream

Posted: Mon Sep 11, 2017 9:18 pm
by vanepico
https://youtu.be/FHU6rCLDdU0

This is a video of my uego next to my nistune readout. I haven't checked the output voltage yet, I was thinking maybe the signal might need a smoothing capacitor, unless like others, the voltage is not the thing causing the fluctuation.