Advertisement
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Home Who's Online Today's Posts HP Calculator CompD Gift Shop Mark Forums Read
Go Back   Competition Diesel.Com - Bringing The BEST Together > Tech- General Diesel > General Diesel Tech
Register Members List Timeslips EFI Live Library Invite Your Friends FAQ Calendar Mark Forums Read

General Diesel Tech Farm equipment, Medium Duty, Big Rigs, and other General discussion can be found in here.

Reply
 
Thread Tools
Old 11-04-2017, 01:17 PM   #1
allan5oh

Name: allan5oh
Title: Too Much Time
Status: Not Here
Join Date: Oct 2012
Member`s Gallery
Posts: 728
Arduino 6 or 8 channel EGT

I'm gonna start playing with Arduino making some sort of EGT display/datalogger. Looks like we need an EGT input shield. The probes put out very little voltage and don't act like a regular 5v sensor at all. Luckily there's EGT shields out there. Single channel Dual channel Four channel Eight channel

Seems as though the 8 channel can only do one every .125 seconds, so you can only read every sensor once a second on an 8 channel unit.

Ocean controls has one too:

https://oceancontrols.com.au/KTA-259.html

Looks neat but doesn't correct for non-linearity. That would have to be done with the code.

I'd like to start off with a simple multi line text display like this:

Standard LCD 20x4 + extras [white on blue] ID: 198 - $17.95 : Adafruit Industries, Unique fun DIY electronics and kits

Then eventually move to touchscreen and logging.
__________________
480 HP to the wheels with a "400 hp" turbo with the fan on to boot. 920f max EGT

Last edited by allan5oh; 11-04-2017 at 01:24 PM.
  Reply With Quote
Old 11-04-2017, 04:52 PM   #2
biggy238
 
biggy238's Avatar

Name: biggy238
Title: Too Much Time
Status: Not Here
Join Date: Aug 2008
Location: Just North of Wrong
Member`s Gallery
Posts: 7,433
Aaaaaaand. I just walked in the door from getting these pictures. I built this 7 years ago and never used it. Click the image to open in full size.Click the image to open in full size.

Sent from my XT1575 using Tapatalk
__________________
Google site:competitiondiesel.com for the gnawlidge.

05.5 Campanella White TDi Jetta 5spd 45.5MPG
-Little Sexy
96 Ext Cab Ram 2500 Long Bed, Test Pig/Science Experiment
- Big Nasty
  Reply With Quote
Old 11-04-2017, 04:57 PM   #3
biggy238
 
biggy238's Avatar

Name: biggy238
Title: Too Much Time
Status: Not Here
Join Date: Aug 2008
Location: Just North of Wrong
Member`s Gallery
Posts: 7,433
I'm going to try and use a Mega ADK because it has USB host mode and hopefully enough timers to handle 8 channels and a display.

Think about including a dimmer function for the backlight on the lcd.

Sent from my XT1575 using Tapatalk
Click the image to open in full size.
__________________
Google site:competitiondiesel.com for the gnawlidge.

05.5 Campanella White TDi Jetta 5spd 45.5MPG
-Little Sexy
96 Ext Cab Ram 2500 Long Bed, Test Pig/Science Experiment
- Big Nasty
  Reply With Quote
Old 11-04-2017, 05:07 PM   #4
biggy238
 
biggy238's Avatar

Name: biggy238
Title: Too Much Time
Status: Not Here
Join Date: Aug 2008
Location: Just North of Wrong
Member`s Gallery
Posts: 7,433
That ocean controls board is sexy.

Sent from my XT1575 using Tapatalk
__________________
Google site:competitiondiesel.com for the gnawlidge.

05.5 Campanella White TDi Jetta 5spd 45.5MPG
-Little Sexy
96 Ext Cab Ram 2500 Long Bed, Test Pig/Science Experiment
- Big Nasty
  Reply With Quote
Old 11-04-2017, 08:49 PM   #5
biggy238
 
biggy238's Avatar

Name: biggy238
Title: Too Much Time
Status: Not Here
Join Date: Aug 2008
Location: Just North of Wrong
Member`s Gallery
Posts: 7,433
Using a Thermocouple | Thermocouple | Adafruit Learning System


Sent from my iPad using Tapatalk
__________________
Google site:competitiondiesel.com for the gnawlidge.

05.5 Campanella White TDi Jetta 5spd 45.5MPG
-Little Sexy
96 Ext Cab Ram 2500 Long Bed, Test Pig/Science Experiment
- Big Nasty
  Reply With Quote
Old 11-04-2017, 09:35 PM   #6
biggy238
 
biggy238's Avatar

Name: biggy238
Title: Too Much Time
Status: Not Here
Join Date: Aug 2008
Location: Just North of Wrong
Member`s Gallery
Posts: 7,433
ArduECU


Sent from my iPad using Tapatalk
__________________
Google site:competitiondiesel.com for the gnawlidge.

05.5 Campanella White TDi Jetta 5spd 45.5MPG
-Little Sexy
96 Ext Cab Ram 2500 Long Bed, Test Pig/Science Experiment
- Big Nasty
  Reply With Quote
Old 11-04-2017, 11:39 PM   #7
zfaylor
 
zfaylor's Avatar

Name: zfaylor
Title: Comp Diesel Sponsor
Status: Not Here
Join Date: Nov 2010
Location: P-TOWN!, Indiana
Member`s Gallery
Posts: 4,536
It is going to get very messy trying to separate a string of 8 probes worth of data to an lcd display. We are working on a color touch screen gauge unit that will data log currently as a side project. I get bored at home at night and I am a sucker for a good headache.

One thing I have learned is that using serial communications is very messy. It can definitely be done, but it gets more difficult when you are separating strings and managing float values and integers. All of which you will likely use since you need to use generic values, send them to a float, convert them to something meaningful, send them in a string, separate the string, make sure the string is ASCii, and then keep it all happy.

Again, it can be done, but you are managing ALOT of information with a project like this. That is the most difficult part. I have a color touch screen version working on the bench. EGT, Boost, Intake temp, and trans temp. We still need to map the values and verify the conversions are accurate, figure out if the display will live without much cooling, cnc a case out, and test the absolute chit out of it. Then we plan to launch it as a viable product.

Data logging is possibly years away for us currently. We can log a string of variables but we want a nice way to utilize the information on the computer side. Information isn't very useful unless you can apply it well. I could hire it out and have it working fairly quick but this is a challenging side project more for myself.

Be ready to pull your hair out alan. Again, this can be done, but doing it well will take a lot of coffee or maybe vodka. I would spend a while learning how the LCD works. That seems to be the most complicated part since it relies on serial communication. I spent a solid month of nights learning it. Everytime I thought I had it dikked I learned I didn't since some nuance would bite me in the azz when I would try to apply it a different way.
__________________
2001 half ton heavy chevy
Wire truck 2nd gen
2003 dodge cummings

North American Turbo
  Reply With Quote
Old 11-04-2017, 11:56 PM   #8
allan5oh

Name: allan5oh
Title: Too Much Time
Status: Not Here
Join Date: Oct 2012
Member`s Gallery
Posts: 728
That's why I wanted to go with the simple character screen instead of lcd/touch screen.
__________________
480 HP to the wheels with a "400 hp" turbo with the fan on to boot. 920f max EGT
  Reply With Quote
Old 11-05-2017, 12:18 AM   #9
zfaylor
 
zfaylor's Avatar

Name: zfaylor
Title: Comp Diesel Sponsor
Status: Not Here
Join Date: Nov 2010
Location: P-TOWN!, Indiana
Member`s Gallery
Posts: 4,536
The simple character screen lcd vs a touch version doesn't matter. They operate on exactly the same principles. You have to tell the LCD what that serial is telling it regardless. They are smart little things but they only know one language and they certainly don't know how to reason. Your code will be the interpreter. It has to know what the information is and where it goes. The only difference from one LCD to the next is the number of pixels that light up for the most part. The libraries help with the general display stuff but past that it is all up to your code.
__________________
2001 half ton heavy chevy
Wire truck 2nd gen
2003 dodge cummings

North American Turbo
  Reply With Quote
Old 11-05-2017, 12:42 AM   #10
allan5oh

Name: allan5oh
Title: Too Much Time
Status: Not Here
Join Date: Oct 2012
Member`s Gallery
Posts: 728
And you're right cataloging isn't about storing data it's about being able to move and present that data easily.
__________________
480 HP to the wheels with a "400 hp" turbo with the fan on to boot. 920f max EGT
  Reply With Quote
Old 11-05-2017, 12:52 AM   #11
biggy238
 
biggy238's Avatar

Name: biggy238
Title: Too Much Time
Status: Not Here
Join Date: Aug 2008
Location: Just North of Wrong
Member`s Gallery
Posts: 7,433
What you are saying is accurate, but it is much much simpler to scroll the data on an LCD. I had my transmission controller programmed to walk "Amore to suck my nuts" across the screen at one point.

You don't need 4 digit resolution on all 8 channels. 2 digit for cylinders and 4 digits for one. If something scares you, read the serial out, or build a simple menu for full res. Grab a 4 button 4X20 for menu control.


Sent from my iPad using Tapatalk
__________________
Google site:competitiondiesel.com for the gnawlidge.

05.5 Campanella White TDi Jetta 5spd 45.5MPG
-Little Sexy
96 Ext Cab Ram 2500 Long Bed, Test Pig/Science Experiment
- Big Nasty
  Reply With Quote
Old 11-05-2017, 01:01 AM   #12
zfaylor
 
zfaylor's Avatar

Name: zfaylor
Title: Comp Diesel Sponsor
Status: Not Here
Join Date: Nov 2010
Location: P-TOWN!, Indiana
Member`s Gallery
Posts: 4,536
Scrolling simple text and separating values received through serial to specific cells is a bit apples to oranges. I scrolled text on my lcd on day 1 of messing with it. There is a sample of how to scroll text in the liquid crystal library. Receiving data and separating the string to specific cells is much much more difficult.
__________________
2001 half ton heavy chevy
Wire truck 2nd gen
2003 dodge cummings

North American Turbo
  Reply With Quote
Old 11-05-2017, 08:01 AM   #13
biggy238
 
biggy238's Avatar

Name: biggy238
Title: Too Much Time
Status: Not Here
Join Date: Aug 2008
Location: Just North of Wrong
Member`s Gallery
Posts: 7,433
I suppose I will have to find out, if I can make time. Be to be clear, I'm not saying specifically to try and scroll, I'm just saying there are ways to display the channels on that size lcd.
I haven't messed with my touch screen in almost two years. I don't think it would be terribly difficult to load a static image on a card and place the numerals in various positions for a nice look.

Also, using that shield over SPI is just one way to go about it. The values could be read directly, although I'm sure there is a reason why they are using the Amp, multiplexer and level shifter. It could be built without the multiplexer. I'm curious why it has the 1 second refresh rate.

Sent from my XT1575 using Tapatalk
__________________
Google site:competitiondiesel.com for the gnawlidge.

05.5 Campanella White TDi Jetta 5spd 45.5MPG
-Little Sexy
96 Ext Cab Ram 2500 Long Bed, Test Pig/Science Experiment
- Big Nasty

Last edited by biggy238; 11-05-2017 at 08:05 AM.
  Reply With Quote
Old 11-05-2017, 10:44 AM   #14
allan5oh

Name: allan5oh
Title: Too Much Time
Status: Not Here
Join Date: Oct 2012
Member`s Gallery
Posts: 728
Thanks for the info guys I really appreciate it. Still in the research and ordering phase. I plan on going deep around Christmas.
__________________
480 HP to the wheels with a "400 hp" turbo with the fan on to boot. 920f max EGT
  Reply With Quote
Old 11-05-2017, 10:46 AM   #15
allan5oh

Name: allan5oh
Title: Too Much Time
Status: Not Here
Join Date: Oct 2012
Member`s Gallery
Posts: 728
Dp..
__________________
480 HP to the wheels with a "400 hp" turbo with the fan on to boot. 920f max EGT

Last edited by allan5oh; 11-05-2017 at 11:00 AM.
  Reply With Quote
Old 11-05-2017, 01:06 PM   #16
biggy238
 
biggy238's Avatar

Name: biggy238
Title: Too Much Time
Status: Not Here
Join Date: Aug 2008
Location: Just North of Wrong
Member`s Gallery
Posts: 7,433
Quote:
Originally Posted by allan5oh View Post
Dp..
Eh?

I meant to elaborate and explain myself. I have to build a unit to handle engine speed conversion for my Ford swap, and would like to tack on Pyro meter and boost sensing and then package it nicely. That ArduECU enclosure is a nice under hood option, and if they roll out with their plans, the options expand quite a bit.

Anyway, my plan is to buy one, plumb everything into the Mini DT connectors and then pipe info into the cabin via SPI or BT.

I'm not sure how well SPI and I2C play together on the same device. Zach might know.

Sent from my XT1575 using Tapatalk
__________________
Google site:competitiondiesel.com for the gnawlidge.

05.5 Campanella White TDi Jetta 5spd 45.5MPG
-Little Sexy
96 Ext Cab Ram 2500 Long Bed, Test Pig/Science Experiment
- Big Nasty
  Reply With Quote
Old 11-05-2017, 01:17 PM   #17
zfaylor
 
zfaylor's Avatar

Name: zfaylor
Title: Comp Diesel Sponsor
Status: Not Here
Join Date: Nov 2010
Location: P-TOWN!, Indiana
Member`s Gallery
Posts: 4,536
SPI and I2C is essentially what we are talking about already. Most of the LCD screens on the market utilize I2C. This is why displaying multiple sensors of information is more difficult than it looks on the surface. I am by NO means an expert on this so take everything with a grain of salt. The multiple layers of conversions is what makes these projects difficult. Both integer conversions as well as language conversions are involved.
__________________
2001 half ton heavy chevy
Wire truck 2nd gen
2003 dodge cummings

North American Turbo
  Reply With Quote
Old 11-05-2017, 01:23 PM   #18
97rada
 
97rada's Avatar

Name: 97rada
Title: Too Much Time
Status: Not Here
Join Date: Feb 2008
Member`s Gallery
Posts: 5,128
Watching. I have wanted to do this for years.
__________________
Austin
tow truck- 97 qclb 5speed. sbdd 3600, 62mm fmw-14.67
toy truck -94 rclb auto- in pieces



Any intelligent fool can make things bigger and more complex...it takes a touch of genius- and alot of courage to move in the opposite direction.
  Reply With Quote
Old 11-05-2017, 06:18 PM   #19
biggy238
 
biggy238's Avatar

Name: biggy238
Title: Too Much Time
Status: Not Here
Join Date: Aug 2008
Location: Just North of Wrong
Member`s Gallery
Posts: 7,433
Arduino - Getting Started

For the creepers.

You can read from there about what Arduino is, how many flavors there are now.

Short synopsis, It is a micro-processor with a physical format and programming language that is geared toward new users. It typically is used as a stepping point for non-production oriented people to bring their ideas to life.
The best Idea I've seen yet is an arduino powered temperature based shower control to run their teenage daughter out of the shower before all of the hot water is gone.

Arduino requires software on your laptop called an IDE (Integrated Development Environment?)
This allows a human to write the code required for the microprocessor to do what you want it to do.
This code is called a Sketch.
Code:
/*
  Blink

  Turns an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
  it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
  the correct LED pin independent of which board is used.
  If you want to know what pin the on-board LED is connected to on your Arduino
  model, check the Technical Specs of your board at:
  https://www.arduino.cc/en/Main/Products

  modified 8 May 2014
  by Scott Fitzgerald
  modified 2 Sep 2016
  by Arturo Guadalupi
  modified 8 Sep 2016
  by Colby Newman

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/Blink
*/

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}
The above example is a basic cornerstone of the Arduino. The boards have LED's built in. You are simply telling one of them to flash ON/OFF (Voltage HIGH, Voltage LOW)

You can Youtube for days. Check out the shift lights and speeduino in particular.

The thing to keep in mind here, you aren't typically going to be able to beat the fit, finish and quality of an existing product that does what you are trying to do. That means one of two things, either you are trying to add features that those products don't offer, or you are mentally deficient.

I'm going to go out on a limb and lump us into the latter half.
__________________
Google site:competitiondiesel.com for the gnawlidge.

05.5 Campanella White TDi Jetta 5spd 45.5MPG
-Little Sexy
96 Ext Cab Ram 2500 Long Bed, Test Pig/Science Experiment
- Big Nasty
  Reply With Quote
Old 11-07-2017, 11:59 AM   #20
joefarmer
 
joefarmer's Avatar

Name: joefarmer
Title: MR. Supreme Overlord
Status: Not Here
Join Date: Jul 2006
Location: ohio
Member`s Gallery
Posts: 5,929
Latter half for me too. Here's code that shows 4 SPI temp probes and 4 I2C CO2 pressure probes in my beer fridge over an ESP8266 running code spit out of an Arduino IDE. The base was a 4 probe BBQ controller, so the code is terribly messy and shouldn't be used by anyone.

huzzah fridge - ThingSpeak IoT

Code:
#include <Wire.h>
#include <Adafruit_ADS1015.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
#include <WiFiUdp.h>
#include "SimpleTimer.h"              // multiple, polled timer events without using a hardware (AVR) timer, but (much) less precision wrt the interval
#include "MCP320x.h"


#define DebugSerial		Serial
#define DEBUG										// enable BLYNK_PRINT and a corresponding serial output to capture the stream

Adafruit_ADS1015 ads;     /* Use thi for the 12-bit version */

/*
   probe and related thermistor defines
   Probe 1 must be connected to A0 and then sequentially from there
*/
#define PROBE1_TEMP				V0				// THIS GROUP MUST BE SEQUENTIAL
#define PROBE2_TEMP				V1
#define PROBE3_TEMP				V2
#define PROBE4_TEMP				V3

#define PROBE1_SETPT				V4				// THIS GROUP MUST BE SEQUENTIAL
#define PROBE2_SETPT				V5
#define PROBE3_SETPT				V6
#define PROBE4_SETPT				V7

#define	PROBE1_LED				V8
#define	PROBE2_LED				V9
#define	PROBE3_LED				V10
#define	PROBE4_LED				V11

#define	CONNECTED_LED			V12

#define	P1_CONNECTED			V13
#define	P2_CONNECTED			V14
#define	P3_CONNECTED			V15
#define	P4_CONNECTED			V16

#define	CLONE_P1					V17


/* ================================= SPI A to D converter MPC3204 ====================== */


#define	ADC_ZERO_THRESHOLD		10				// threshold value for a zero reading (capacitance?)
#define ADC_SAMPLES        		5				// number of sames to taken when reading analog ports for temp values

MCP320x MCP(SS);								// see pins_arduino.h for ESP8266/Huzzah - using only 1 parameter forces SPI MODE (uses SPI library)

/* ================================= sketch ======================== */

/*
   Steinhart-Hart coefficients obtained empirically from the calibration utility for the Maverik ET-73 200k ohm probe
   See https://en.wikipedia.org/wiki/Steinhart-Hart for reference and readTemp() below
*/
#define	A						0.001433954477
#define B						0.000076877069
#define C						0.000000537597


/*
   other defines
*/
#define	PROBE_COUNT			4				// number of temperature probes 
#define	ADC_RESOLUTION		4095			// ADC resolution: depends on the platform. Mega/Uno is 10 bits, so (2^10)-1 = 1023. This is for the 12-bit MPC3204 SPI ADC



/*
   data associated with each temperature probe
*/
typedef struct {
	uint16_t		Setpoint;					// setpoint
	uint16_t		SavedSetpoint;				// copy to save for a disconnected probe
	uint16_t		CurrentTemp;				// current temperature. 
  float       dCurrentTemp;        // current temperature. 
	uint8_t		SetpointReached :1;		// if set temperature has been reached
	uint8_t		Present         :1;		// true if probe is connected
	uint8_t		TempChanged     :1;		// true if temp has changed - throttles updates to Blynk dashboard
} ProbeType;

ProbeType Probe[PROBE_COUNT];
uint32_t seriesResistor[PROBE_COUNT] = { 197900, 200500, 197800, 198800 };		// Measured series resistor value in ohms. Must be the SAME as the nominal 25deg C resistance of the probe


/* ================================================== Timer functions =========================================================================== */

// stagger the intervals to allow time for the server messages to complete. Also, use primes in case that helps.
#define	SETPT_DELAY			1609			// how often setpoints are checked in msec
#define PROBE_DELAY			1009			// how often probe temperatures are read in msec
#define TEMP_DELAY			1289			// how often dashboard temperature display values are pushed

#define LCD_DELAY				3049			// how often physical LCD is updated (slow enough to minimize flicker)
#define PUSH_DELAY			300000			// how often push notifications for setpoint reached are done in msec


SimpleTimer timer;

/* ==========================================================  GENERAL ================================================================================ */

bool	redrawScreen = false;							// set when a screen redraw is needed
bool	firstConnect = true;							// true after we have connected once


 // ThingSpeak Settings
  char thingSpeakAddress[] = "api.thingspeak.com";
  String writeAPIKey = "yourkeyhere";
  const int updateThingSpeakInterval = 30 * 1000;      // Time interval in milliseconds to update ThingSpeak (number of seconds * 1000 = interval)


void setup ( void ) {

#if defined(DEBUG)
	DebugSerial.begin(9600);
	while ( !DebugSerial );
#endif // DEBUG
	

	MCP.setMCPConfig(MCP_SINGLE, MCP_ALL_PORTS);			// single mode for all MPC3204 pins

	/*
		Program flow:
		
		Event										Handler				Dashboard updated
		-----------------------------   -------------------   ----------------
		Setpoint set in dashboard			BLYNK_WRITE()			YES
		Probe temperature change			updateProbes()
		Probe removed							updateProbes()			(YES)
		Probe re-inserted						updateProbes()			(YES)
		Dashboard Temp display update		updateTemps()			YES
		Setpoint reached						updateSetpoints()
		Dashboard setpt LED updated		updateSetpoints()		YES
		Setpoint push notices				sendPushNotices()
		LCD updated								updateLCD()
	*/

	timer.setInterval(SETPT_DELAY, updateSetpoints);
	timer.setInterval(PROBE_DELAY, updateProbes);
	timer.setInterval(LCD_DELAY, updateLCD);
	timer.setInterval(PUSH_DELAY, updateThingspeak);

 WiFi.mode(WIFI_STA);

   ads.begin();
}

/*
 Check current values to see if probe setpoints have been reached
 Note that for the setpoint flag to be set, it must be present. Thus, we don't need to check this in other functions
 Also updates Blynk dashboard setpoint LEDs
*/
void updateSetpoints ( void ) {
	for ( uint8_t i = 0; i < PROBE_COUNT; i++ ) {
		if ( Probe[i].Present ) {
			if ( (Probe[i].Setpoint > 0) && (Probe[i].CurrentTemp >= Probe[i].Setpoint) ) {
				Probe[i].SetpointReached = true;
			} else {
				Probe[i].SetpointReached = false;
			}
		}
	}
}


/* 
   Derive the resistance of the probe to use in the Steinhart-Hart eqution.
   We can do this given the known value of the series resistor in the fixed part of the voltage divider
   and the fact that since V = I*R the voltage drop on each resistor is directly proportional to voltage.
   Thus, we can use a ratio to determine the resistance of the probe without using the reference voltage which can vary considerably from 5V.
   Also, this allows us to use the same code on 5V or 3.3V platforms :-) as well as just working with the digitized reading without any voltage conversions.
   
   NOTE: both float and double on Arduino are 32-bit values. No difference between the two.
*/
float calcResistance ( const uint8_t pin ) {
	float reading = 0;

	for ( uint8_t i = 0; i < ADC_SAMPLES; i++ ) {
		reading += MCP.readChannel(pin);
	}
	if ( reading >= ((ADC_RESOLUTION * ADC_SAMPLES) - 20)) {
		// probe disconnected
		return 0;
	} else {
		reading /= (float)ADC_SAMPLES;
		reading = (ADC_RESOLUTION / reading) - 1;
		return (seriesResistor[pin] / reading);
	}
}

/*
  get the normalized raw value of the probe on the given pin for debug
  note that a disconnected probe will return 0 
*/
uint16_t probeRaw ( const uint8_t pin ) {
	uint16_t reading = 0;

	for ( uint8_t i = 0; i < ADC_SAMPLES; i++ ) {
		reading += MCP.readChannel(pin);
	}
	reading /= ADC_SAMPLES;
	return reading;
}

/*
   read the temperature from the given analog pin and return temperature in degrees F
   uses the Steinhart-Hart equation
   Note: when using constants in float calculations, make sure there is a decimal point
*/
float readTemp ( const uint8_t pin ) {
	float R, kelvin;

	R = calcResistance(pin);
	if ( R == 0 ) {
		// probe disconnected
		return 0;
	} else {
		kelvin = 1.0/(A + B*log(R) + C*pow(log(R), 3.0));
		return ((kelvin  * (9.0/5.0)) - 459.67);				// K to F conversion
	}
}

/*
  Get current probe temps
  Check for probes that have been disconnected or reconnected
     - update Blynk dashboard if probe status has changed
*/
void updateProbes ( void ) {
	for ( uint8_t i = 0; i < PROBE_COUNT; i++ ) {
		uint16_t temp = (uint16_t)readTemp(i);
      Probe[i].dCurrentTemp = readTemp(i);
		
		// get probe temps & handle disconnects/reconnects
		if ( temp != Probe[i].CurrentTemp ) {
			Probe[i].CurrentTemp = temp;
			Probe[i].TempChanged = true;
		}
		if ( (Probe[i].CurrentTemp == 0) && Probe[i].Present ) {
			/*
			   probe disconnected:
			   push dashboard setpoint slider value
			   temperature will be updated with the next BLYNK_READ of the probe temp
			*/
			Probe[i].Present = false;
			Probe[i].Setpoint = 0;
			Probe[i].SetpointReached = false;
			redrawScreen = true;
		} else  if ( (Probe[i].CurrentTemp > 0) && !Probe[i].Present ) {
			// reinserted - reset to previous setpoint
			Probe[i].Present = true;
			Probe[i].Setpoint = Probe[i].SavedSetpoint;
			redrawScreen = true;
		}
	}
}

/*
 Update the physical LCD display
 This happens even when Blynk is offline
 Periodically display an offline message when Blynk is offline
*/
void updateLCD ( void ) {
	static uint8_t	offlineCount = 0;

	if ( redrawScreen ) {
		redrawScreen = false;
	}
 
  for(int i = 0;i < PROBE_COUNT; i++ )
  {
    DebugSerial.print("field"); 
    DebugSerial.print(i+5);
    DebugSerial.print("=");
    DebugSerial.print(ads.readADC_SingleEnded(i) * 0.0255);
    DebugSerial.println("&"); 
  }
}

int status = WL_IDLE_STATUS;
void updateThingspeak ( void ) {
    if ( status != WL_CONNECTED) { 
      DebugSerial.println("Couldn't get a wifi connection");
      WiFi.printDiag(Serial);
      status = WiFi.begin("SSID", "mypw");
    } 
    else {
      WiFiClient client;
      while(!client.connect("api.thingspeak.com", 80)) {
        DebugSerial.print(".");
      }

      String temps = readTemps();
      
      // Make a HTTP request:
      client.print("POST /update HTTP/1.1\n");
      client.print("Host: api.thingspeak.com\n");
      client.print("Connection: close\n");
      client.print("X-THINGSPEAKAPIKEY: "+writeAPIKey+"\n");
      client.print("Content-Type: application/x-www-form-urlencoded\n");
      client.print("Content-Length: ");
      client.print(temps.length());
      client.print("\n\n");
      client.print(temps);
      
      client.stop();
      client.flush();
      DebugSerial.println(temps);
    }
}

String readTemps() 
{ 
  String temp;
  
  for(int i = 0;i < PROBE_COUNT; i++ )
  {
    temp += "field"; 
    temp += (i+1);
    temp += "=";
    temp += Probe[i].dCurrentTemp;
    temp += "&"; 
  }

  for(int i = 0;i < PROBE_COUNT; i++ )
  {
    temp += "field"; 
    temp += (i+5);
    temp += "=";
    temp += ads.readADC_SingleEnded(i) * 0.0255;
    temp += "&"; 
  }
   
  return temp;
}

/*
 LOOP
*/
void loop ( void ) {
	yield();
	timer.run();
}
__________________
brandon'); DROP TABLE Users;--
49 Dodge 1.5t 12v RH swap | 99 F250 12v RE test rkt | 11 X5 'no soup'
firepunk.com
  Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 09:43 PM.

 


Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Copyright ©2006 - 2018, CompetitionDiesel.com
all information found on this site is property of www.competitiondiesel.com