PDA

View Full Version : Arduino boost gauge



Mad Cow
08-18-2014, 06:34 PM
I've been working on this for a few weeks now, finally got to a stage where it works and looks half-decent. I wanted a digital boost gauge but didn't want to pay $100 for some ugly round gauge that I have to mount to an equally ugly pod, so I made one myself. The hardware is really simple, just an Arduino and an LCD. I tapped into the stock boost sensor for the time being, later I'll hook up a separate sensor to the IM so that it can also measure vacuum. Power is provided by a homemade 9v regulator since I don't feel safe pumping 14v through the Arduino. The beauty of this setup is you can mount it basically anywhere you want so long as the LCD fits, mine's in the pop-out cupholder slot since I don't use it anyway.

http://i.imgur.com/vZmyZiA.jpg?1
Terrible picture, but you get the idea. It's not fully mounted yet, it's just sandwiched in there kinda crooked for a test fit.

The top row shows boost to the nearest 0.5 psi, the bottom row is a bar that grows with boost so I can have a quick visual reference along with a concrete number.

This is the code as of now:



#include <MedianFilter.h>
#include <LiquidCrystal.h>
#include <LcdBarGraph.h>

float BoostPSI = 0;
int GraphVal = 0;
int MAPin = 0;
float BoostKPa = 0;
float vacInHg = 0;

MedianFilter Filter;
int FilterIN;
int FilterOUT;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(9, 8, 5, 4, 3, 2);
LcdBarGraph lbg(&lcd, 16, 0, 1); // -- creating bargraph instance

void setup()
{
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
pinMode(6,OUTPUT);
analogWrite(6, 85); // LCD contrast ---Usable range 60-100---
Filter.begin();

// Splash screens
lcd.print("Boost Gauge");
lcd.setCursor(0, 1);
lcd.print("By Wiseguys Inc");
delay(1250);
lcd.clear();
}


void loop()
{
FilterIN = analogRead(0);
FilterOUT= Filter.run(FilterIN);

// Boost formula
BoostKPa = (float)((FilterOUT - 40.96) / (1.3166592));
vacInHg = ((BoostKPa * 0.295301) * -1 );
BoostPSI = (BoostKPa * 0.145);


// Rounding to 0.5
BoostPSI = (BoostPSI * 2);
BoostPSI = round(BoostPSI);
BoostPSI = (BoostPSI / 2);

vacInHg = (vacInHg * 2);
vacInHg = round(vacInHg);
vacInHg = (vacInHg / 2);

// Boost graph
GraphVal = (int)(BoostKPa);
if (GraphVal < 0) GraphVal = 0; //Prevent graph from flipping its shit
lbg.drawValue(GraphVal, 140); // Limits graph to 140 kPa, approx 20 psi


// Print values
if (BoostKPa > 0)
{
lcd.setCursor(0, 0);
lcd.print(BoostPSI);
}
else
{
lcd.setCursor(0, 0);
lcd.print(vacInHg);
}

if (BoostPSI < 10)
{
if (BoostPSI < 0)
{
lcd.setCursor(5, 0);
lcd.write(254);
}
else
{
lcd.setCursor(3, 0);
lcd.write(254);
lcd.setCursor(4, 0);
lcd.write(254);
lcd.setCursor(5, 0);
lcd.write(254);
}
}
else
{
lcd.setCursor(4, 0);
lcd.write(254);
lcd.setCursor(5, 0);
lcd.write(254);
}

if (BoostKPa > 0) //Print PSI or InHg depending on reading
{
lcd.setCursor(6, 0);
lcd.print("PSI");
lcd.setCursor(9, 0);
lcd.write(254);
lcd.setCursor(10, 0);
lcd.write(254);
}
else
{
lcd.setCursor(6, 0);
lcd.print("In.Hg");
}

delay(100); // prevents LCD from ghosting.
}


If anyone else wants to make one of these I can go into more detail and answer any questions, I decided to keep it brief at first because everything you need to know can be found after a quick google search. I based mine mostly off these two (http://www.seatcupra.net/forums/showthread.php?t=348592) links (http://cstark27.blogspot.ca/).

All in all it's cost me around $50 for everything. Next step is to switch to a separate pressure sensor and a barometric pressure sensor to accurately compensate for atmospheric pressure, then add a VDO oil pressure sender into the mix. I don't wanna reveal my final plans just yet in case it turns out to be too difficult, but if it's possible it'll be glorious

EDIT: Latest code added.

Poopie
08-18-2014, 06:44 PM
I was working on the same thing. I'll got part through the code the I got a touch panel and I was developing a menu system for boost level selection and then I got engaged and put it on the side.


I'll look at the code when I get to a comp n

A4Moby
08-18-2014, 11:05 PM
Is the sensor linear? Where did you get the formula for the sensor?

rodgertherabit
08-19-2014, 06:59 AM
Thisis fucking awesome and makes me wish I knew how to do this kind of stuff!

Poopie
08-19-2014, 07:11 AM
ok first question is, what sensor are you using?

MAP will only measure boost and not vacuum. Thats why you are reading 1-2 psi at cruising speed due to your correction factor for altitude. I would code the correction out for now.

I used this sensor. I don't know the voltage range though. I'll check when i get home.

http://www.ebay.com/itm/Electronic-TURBO-Boost-Gauge-Meter-Sender-Sensor-1-8-NPT-Universal-Bar-Psi-/360523710421?pt=Vintage_Car_Truck_Parts_Accessorie s&hash=item53f0e33fd5&vxp=mtr

it is nice and cheap and it will measure down to -1 bar for vac readings.

Anyway regarding your boost formula, you are gonna have to walk me though your thought process. If it was me, i would just scale the sensor voltage and convert it to PSI and be done with it and not even worry about altitude correction for now. Luckily most sensors are 0-5 V anyway. So you probably know this, but the arduino runs off a 10 bit processor meaning it can take a range 1024 measurements per input. This will limit its resolution, but for most instances it is plenty. Get the arduino to read the voltage off the sensor, then manipulate the numbers to convert to PSI.

For example: say an analog read of the sensor yields a value of 750. The micro has no idea what thats means, it is value and has no unit. you can convert that to a voltage which is a step in the right direction.

a value of 750 is 3.66 volts because voltage= mapsen * (5.0 / 1023.0)
Then you can correlate 3.66 volts to a specific PSI reading using a map command.

http://arduino.cc/en/reference/map

hope this points you in the right direction. After you get your boost readings down you can use the PWM output to control a MAC solenoid for boost control. You can play around with pulse width and duty cycle to dial in boost.

Mad Cow
08-19-2014, 07:57 AM
Thanks for the help, yea my formula is a massive mess because I was basically going blindly through trial and error until I came up with something that made a bit of sense. I actually found out about the map function and stock sensor's response curve not long after I posted and am working on completely revamping the boost calculations, basically I used the constrain function to limit values to the upper and lower voltage limit of the MAP sensor, mapped those values from 40 to 500 (the sensor's min and max reading in kPa * 2, could increase it to * 3 if needed). Looking back I feel like an idiot for going the complicated and hacky route but that's how you learn I guess. I've lowered the resolution so much because the full 10 bits seem way unnecessary and I've had to implement a whole lot of smoothing and hackery just to get the displayed boost to not jump around wildly.

As for the atmospheric pressure adjustment, that way I understand is that no MAP sensor can measure an actual vacuum, they instead measure a positive absolute pressure and then subtract atmospheric pressure from that to get a vacuum value. If I take out the adjustment it'll read 14.7 psi too high.

A4Moby
08-19-2014, 09:20 AM
If the sensor varies voltage instead of resistance then it probably is linear and a linear conversion from voltage to psi works. The couple of variable voltage sensors that I've used in the past with a car pc/phidgets project (oil pressure for example) have been. But it would still be nice to understand the physical characteristics of the sensor you are using to be sure. I don't have Bentley in front of me but it may have this as part of testing the sensor to determine if it is bad.

Edit: something like this for the sensor is what I mean - http://injector-rehab.com/shop/mapsensor.html

Mad Cow
08-19-2014, 11:32 AM
I found this: http://s4wiki.com/wiki/Manifold_air_pressure#Transfer_function, the first curve is the sensor our cars use. Just took it out for a test run and it's sitting at 1-1.5psi at rest, which I'm assuming is from an inaccurate altitude correction, need to buy that barometric pressure sensor soon.

walky_talky20
08-19-2014, 11:58 AM
Altitude sensor-corrected digital boost gauge?

Noice.

Also, this thread needs an embedded YouTube video like...stat.

Poopie
08-19-2014, 02:18 PM
https://www.youtube.com/watch?v=WeAaWL4AtQU

special surprise on the slash screen.

heres was mine breadboarded. Layout was rough and i was playing with a menu system at the time. i'll dig mine up later and see if i can make a better video and post the code.

walky_talky20
08-19-2014, 02:23 PM
- Could something like this theoretically do several data points on-screen at once? Like Boost, AFR, IAT, and Oil pressure?
- How is the readability?
- Can you change brightness for Day/Night?

What is funny is that I have a full XP desktop PC in my car with a 7" VGA touchscreen, but I am still really interested in this little display.

Poopie
08-19-2014, 02:33 PM
- Could something like this theoretically do several data points on-screen at once? Like Boost, AFR, IAT, and Oil pressure?
- How is the readability?
- Can you change brightness for Day/Night?

What is funny is that I have a full XP desktop PC in my car with a 7" VGA touchscreen, but I am still really interested in this little display.

yeah you can display all you want. You are limited to 6 inputs on the base atmega328 micro.

readability is fine. There are many displays you can use. the TFT and oled ones are pretty good too

depending on the LCD, you can control brightness and you can use an input on the micro for a photoelectric sensor for day night adjustment, or manually by tapping into a 12v source. Use a voltage divider so you don't fry the board. Then it comes down to a few lines of code.

Mad Cow
08-19-2014, 02:48 PM
yeah you can display all you want. You are limited to 6 inputs on the base atmega328 micro.

readability is fine. There are many displays you can use. the TFT and oled ones are pretty good too

depending on the LCD, you can control brightness and you can use an input on the micro for a photoelectric sensor for day night adjustment, or manually by tapping into a 12v source. Use a voltage divider so you don't fry the board. Then it comes down to a few lines of code.

You can buy a multiplexer shield that will give you like 40 inputs, and I'm pretty sure you can run more than one of those at a time so the number of inputs is barely an issue.

My LCD is a perfect match to all the stock LCDs at night, but in direct sunlight it's all washed out and glary. I really wish it was brighter. I've got my eye on a colour TFT the exact same physical size as the stock cluster LCD, you can probably guess where I'm going with this.

Poopie
08-19-2014, 02:51 PM
You can buy a multiplexer shield that will give you like 40 inputs, and I'm pretty sure you can run more than one of those at a time so the number of inputs is barely an issue.

My LCD is a perfect match to all the stock LCDs at night, but in direct sunlight it's all washed out and glary. I really wish it was brighter. I've got my eye on a colour TFT the exact same physical size as the stock cluster LCD, you can probably guess where I'm going with this.


haha yeah i had info about multiplexing in there originally, but i left it cause i feel like it would raise too many questions and didn't want to get into how they work.

walky_talky20
08-19-2014, 03:11 PM
Poopie, you can hit us with the gory details.

We can take it. [;)]

Poopie
08-19-2014, 03:46 PM
i guess its similar to can-bus in the aud/vw system. can-bus works over digital signals over a single stream of data. signals are precisely timed and associated with an address and a controller knows what each ping means.

a mux works kinda the same. a multiplexer gathers the inputs at a set frequency and spits it out into a single signal. Then a demultiplexer interprets it and breaks it back out to multiple channels. think about your neighborhood how there is a single telephone wire going out and it carries multiple phone conversations at the same time. its breaking up the voice data down so fast you don't even notice. but what you are actually hearing is broken up bits on sound so fast that it sounds smooth.

Bikeboy7890
08-19-2014, 08:00 PM
Arduino's and other microcontrollers also have built in SPI and I2C buses, great for loads of fun I/O niceties. A company called SEEED Studio actually makes an add on to the arduino for reading CAN-BUS traffic. If you can figure out what traffic you are looking for, you can read many of the signals that the ECU gets. (Not sure how exactly the Audi CAN-BUS system is set up).

I have wanted to do this project ever since I bought my A4 last August. As soon as I get another crank position sensor, and a new clutch, I want to design my own microcontroller based LCD to go either where you have yours in that stupid cup holder slot (mine is broken) or 3D print a bezel for it to fit in the center vent location.

With the controller stowed away under the dash for easy access. I've been looking everywhere for the MAP sensor data, so thanks so much for that!

Edit, broken up for readability

A4Moby
08-19-2014, 10:47 PM
- Could something like this theoretically do several data points on-screen at once? Like Boost, AFR, IAT, and Oil pressure?
- How is the readability?
- Can you change brightness for Day/Night?

What is funny is that I have a full XP desktop PC in my car with a 7" VGA touchscreen, but I am still really interested in this little display.

I'm in the same boat. In my last project car I ran a car PC with Centrafuse as a front end, and then wrote all the code to integrate oil pressure, temp, Innovate LC1 wideband A/F, J&S knock sensor output... into the Centrafuse screens using a Phidgets 8/8/8 for sensor input over USB. I'm about to swap my partial facelift console to a facelift console so that I can install my doubledin touchscreen and my car PC, but the simplicity of the Ardunio approach is tempting. I'll still go the car PC route because i need to replace my headunit and the ability to have alll nav, music, tuning, hands free phone... in one place is ultimately better for me (and also because I'm a longtime programmer at a certain company in Redmond so this is my bread and butter :-)).

At any rate given that you already have a car PC if you just want to display sensor data to it take a look at the Phidgets (http://www.phidgets.com/) stuff to get the inputs to the PC. They are as easy to get data from as Arduino, with libraries in lots of languages - C/C++, JavaScript, VB, python, C#...

walky_talky20
08-20-2014, 09:29 AM
^Thanks Moby.

I think the allure of the micro-controller thing is that it's simple and can be added to any car. You don't need a PC to run it. If I put in the time to make it all work, I could easily give the code to someone else who could cheaply add it to another car. Makes the development more worth it.

Also my current LCD panel kinda sucks. It's LED backlit, but not transflective. That stuff was just coming out when I put it together. So seeing any kind of important data during the day is sketchy.

fed0ra
08-20-2014, 09:53 AM
This is so awesome! Something I've been interested in doing is use an Arduino with two-three monochrome OLED screens (should be good in daylight or at night) to display data from a wideband O2 sensor, IAT and EGT. The screens I was looking at should accommodate one-two sensor outputs without the text being too small (I want it to be visible with a quick glance) and would fit within a single din slot. You could fit 3, I think, but I may be able to do what I want in 2. A simple enclosure could be made to house the arduino and the displays that fits in a single din slot, so with an aftermarket single din radio you now have a customizable, easily removable digital gauge system.

I have read that wideband O2 sensors are difficult to read from, which is why they are pricey, but I think it could be easy to do. My idea: take a Bosch LSU 4.2 sensor (like the kind that 2001 and up 1.8Ts use in the front slot) and replace the rear O2 sensor with it but send the signal output and ground to the arduino instead of the ECU (and resistor the connections to the ECU). I found the formula for converting the output current to lambda, so using that and a simple lambda to AFR equation you now have an accurate AFR reading. Simple and quick? Definitely not. Totally possible, cheaper than a UEGO or LM-1 and customizable? Absolutely.

If anyone else is interested, here is the screen I am hoping to use (https://www.adafruit.com/products/938) and the documentation on the LSU 4.2 sensors is here (http://www.etas.com/en/downloadcenter/5858.php).

walky_talky20
08-20-2014, 10:04 AM
In my father's racing endeavors (mini-stock and enduro), we have discussed the need for an automatic transmission 'controller' of sorts. We find that stock TCU's do not always function as desired for racing (ie: can't hold a gear, refuse to downshift, etc.). Smooth shifting is not necessary, but something to control the solenoids adequately with some limited amount of logic would be ideal. We are thinking flappy-paddles in a 97 V6 Accord, here. I thought an Arduino would be the perfect thing for this, but I need a simpler project to get my feet wet before jumping straight into PWM control. This gauge thing might be the ticket.

fed0ra
08-20-2014, 10:21 AM
We should create some sort of repository so we can all access each others projects and build off of them. Would anyone be interested in a Git repository? For anyone unfamiliar with Git it is a revision control system and we could all upload our Arduino code with documentation on hardware used, etc.. From there anyone could "check out" the code and use it in their own project and then add their code to the repository. This would (hopefully) result in a community code library for Arduino or Raspberry Pi or whatever you want to use that we could all build off of and improve.

Mad Cow
08-20-2014, 10:36 AM
We should create some sort of repository so we can all access each others projects and build off of them. Would anyone be interested in a Git repository? For anyone unfamiliar with Git it is a revision control system and we could all upload our Arduino code with documentation on hardware used, etc.. From there anyone could "check out" the code and use it in their own project and then add their code to the repository. This would (hopefully) result in a community code library for Arduino or Raspberry Pi or whatever you want to use that we could all build off of and improve.

That would be a great idea, I've never used git before though so it's probably best I stick to just contributing.

Bikeboy7890
08-20-2014, 10:58 AM
I'm in the same boat. In my last project car I ran a car PC with Centrafuse as a front end, and then wrote all the code to integrate oil pressure, temp, Innovate LC1 wideband A/F, J&S knock sensor output... into the Centrafuse screens using a Phidgets 8/8/8 for sensor input over USB. I'm about to swap my partial facelift console to a facelift console so that I can install my doubledin touchscreen and my car PC, but the simplicity of the Ardunio approach is tempting. I'll still go the car PC route because i need to replace my headunit and the ability to have alll nav, music, tuning, hands free phone... in one place is ultimately better for me (and also because I'm a longtime programmer at a certain company in Redmond so this is my bread and butter :-)).

At any rate given that you already have a car PC if you just want to display sensor data to it take a look at the Phidgets (http://www.phidgets.com/) stuff to get the inputs to the PC. They are as easy to get data from as Arduino, with libraries in lots of languages - C/C++, JavaScript, VB, python, C#...


PLEASE tell me this is programming for Nintendo America. Please Please Please. :)

Bikeboy7890
08-20-2014, 11:39 AM
Also, I am interested in a Git repository as well, though I have not used it before either

A4Moby
08-20-2014, 12:24 PM
PLEASE tell me this is programming for Nintendo America. Please Please Please. :)

No, I've been a software engineer/lead software engineer at Microsoft since '99, working on severs (BizTalk), the .Net programming framework (3.0-4.5), Xbox Live, and currently our core online commerce services that drive all online purchasing (Xbox, Phone, Windows Store, Microsoft Store, Office, Azure...). If you need GUI code I'm not it, but if you need concurrent, multi-threaded servers, high scale services, or programming frameworks/libraries, that's what I do best.

A4Moby
08-20-2014, 12:27 PM
Also, I am interested in a Git repository as well, though I have not used it before either

+1. I have used GIT. I'd likely port to c# for my car pc but could both add that back for others or contribute bug fixes.

fed0ra
08-20-2014, 12:51 PM
That would be a great idea, I've never used git before though so it's probably best I stick to just contributing.


Also, I am interested in a Git repository as well, though I have not used it before either


+1. I have used GIT. I'd likely port to c# for my car pc but could both add that back for others or contribute bug fixes.

I'm not a master of Git but I've used it for some stuff in the past; it will be a learning experience for everybody. Both companies I've worked for have used SVN but we all wanted to switch over to Git because its a little more user friendly.

So, here it is: https://github.com/audizine-community-org/audizine-community-code. I created the repository under the organization "audizine-community-org" which I'm currently the owner of. There is a README in the repository that has some info and explains the process for joining the organization. If anyone else is more adept with Git and wants to join as an owner let me know. You should be able to fork the repository without being a member but you won't be able to commit as far as I know.

A4Moby
08-20-2014, 05:00 PM
Mad Cow - 2 questions

Where did you tap the stock sensor?

For the code itself why are you using 40 as the lower limit but 500 as the upper when you map from the Arduino sensor reading to voltage? I would have thought either 0,500 (the raw range of the sensor) or 40,465 (the acceptable range of sensor output) would be two options. I wonder if the fact that you are using the lower of the accept range but the upper of the raw range is slightly skewing your readings. It's not a big difference, I'm mostly just wondering if there is something that I'm missing.

Edit: I also found this reference (http://www.msextra.com/doc/ms3/genericsensors.html) useful when I was first doing my carpc/Phidgets pressure sensor project. They have an example formula for the 4250A and also for the Honeywell 0-100 pressure sensor that I used for oil pressure monitoring. Worked great.

Edit2: again, I may be misreading, but as i looked over that link in the first edit I think that you need 2 range maps. The first would be raw digital form of the analog value that analogRead gives you to voltage (this is what you have) and then another from voltage to bar (value, 40, 465, .2, 250). Then from bar to psi. Again, I could very well be missing something, I find coding and tablets don't mix well.

Corrado_Guy
08-20-2014, 07:07 PM
This is kind of similar.... http://arduinodev.com/hardware/obd-kit-2/

Mad Cow
08-20-2014, 08:20 PM
Mad Cow - 2 questions




I tapped into the sensor at the ECU connector. For the sensor scaling, what I did was limit values to the upper and lower voltages as per the transfer function I posted earlier
MAPin = constrain(MAPin, 81, 952); -- 0.4v and 4.65v

I then mapped those values to a range corresponding to the range of the MAP sensor (20 to 250 kPa), multiplied by 2, which I later divide by 2
BoostKPa = map(average, 81, 952, 40, 500);

I basically skipped the raw input - voltage conversion by finding the raw input values that correspond to the upper and lower voltages and using those instead. I multiplied BoostKPa by 2 to preserve some resolution since the map function uses integer math. It makes sense in my head but again I'm no coder, my experience involves a VBA class I took in university and that's it.

I think something's screwy with my code though, I was driving yesterday and after about 20-25 minutes (not sure exactly since I wasn't paying attention) the screen basically froze showing garbled stuff where the boost value goes, switching between 2 unintelligible symbols every few seconds, the graph stopped working, and I could faintly see a flashing cursor on the very right of the bottom row. Everything was fine after a restart though, so hopefully it was just one of the LCD data pins losing connection for a split second and screwing up the signal timing thereafter.

A4Moby
08-21-2014, 10:30 AM
Gotcha, I misunderstood what the 40 and 500 represented.

Debugging languages and environments like this are a little challenging. Based on your description you are ending up with values that aren't in the decimal ascii range. When you print it is taking a value and converting it to a character. If the value is decimal 1 that corresponds to the ascii charater 1. But if the value is 244 that corresponds to a different acsii character (there are non alphanumeric ASCII chars, like space, line feed, carriage rerun, and symbols), and that is what is printed. This means that one of your steps calculated an out of range value. Perhaps an int overflow, divide by 0...

Best bet is to start adding "assertions" to try to determine which step is outputting the bad value. This means things like do I have a positive number after an operation? Is this value within the range that I expect. For a very simple environment like this with no way to log the output you could give every assertion or check that you add a number. If one of them fails you could write a simple message to the LCD with the number of the assertion that failed and break out of the loop. That way while driving you can see, oh, number 5 failed, go back and check what that assertion is checking, and then try to work back up the code to see how it got values that caused it to fail.

If I where to take a blind guess I would temporarily get rid of the smoothing array. And if it will only ever have 2 slots I'd reduce the complexity by just making current and last variables.

Mad Cow
08-21-2014, 11:05 AM
Thanks for the advice, I'm thinking it has to do with the smoothing too. That's the only code that I straight up copy-pasted from an example, I was using 5 steps for it in the beginning but now I might even fully take it out since it's not doing much anymore. Either that or it could be my fast and loose use of int and float variables all over the place. For the assertions, you're talking about basically adding in if statements after each major operation right?

Bikeboy7890
08-21-2014, 11:17 AM
No, I've been a software engineer/lead software engineer at Microsoft since '99, working on severs (BizTalk), the .Net programming framework (3.0-4.5), Xbox Live, and currently our core online commerce services that drive all online purchasing (Xbox, Phone, Windows Store, Microsoft Store, Office, Azure...). If you need GUI code I'm not it, but if you need concurrent, multi-threaded servers, high scale services, or programming frameworks/libraries, that's what I do best.

I had no doubt that Microsoft was the place for you. I respect coders, but as a computer engineering student, if it is not hardware or assembly, it doesn't quite hold the same type of enjoyment for me. Thought I am doing some PLC work for my internship currently, and it is actually pretty cool, yet challenging.

fed0ra
08-21-2014, 11:37 AM
I agree with A4Moby on leaving out the smoothing array. It will probably just cause more trouble then you need.

Also, as far as the ints/floats are concerned the only place it may be an issue is when you use int average as an input to a function that returns a float (the "map" function). I found this forum post about the map function (http://forum.arduino.cc/index.php/topic,3922.0.html) and apparently you can't directly return the map function as a float like you have it. I would suggest changing BoostKpa to an int and then mapping it to a float like this: float someOtherVariable = (float)BoostKpa. I think you might be upsetting the map function with certain values and thats what is causing the strange behavior you've been seeing. Worth a shot [up].

A4Moby
08-21-2014, 11:49 AM
For assertions, yes, basically just add if statements that "assert" that the result of the step is a value or range that you expect it to be. If not write to the LCD some indicator that the assertion failed (and which one it was).

ricekikr
08-22-2014, 03:46 AM
Can this be used to switch a relay based on a uego + rpm + psi (or rpm + 2 5v sensors)?

Poopie
08-22-2014, 06:37 AM
yes you can. its a controller so all you need to do some come up with the logic. you might have enough juice to turn on a solid state relay of the arduino board, but i would get a dedicated power supply and run stuff off a transistor.

Mad Cow
08-22-2014, 06:51 AM
Can this be used to switch a relay based on a uego + rpm + psi (or rpm + 2 5v sensors)?

It can be used for literally anything, the only limit is your imagination and skills.

I'll try taking out the smoothing and fix the float in the map function, I had a bad feeling about that but couldn't think of a better way.

ricekikr
08-22-2014, 07:25 AM
yes you can. its a controller so all you need to do some come up with the logic. you might have enough juice to turn on a solid state relay of the arduino board, but i would get a dedicated power supply and run stuff off a transistor.


It can be used for literally anything, the only limit is your imagination and skills.


Anywhere cheap I can get a kit or better just piece it together?

edit: would this work? $11. Don't need the lcd

Mad Cow
08-22-2014, 07:39 AM
Link don't work, but for starting I'd recommend the Leonardo (http://store.arduino.cc/product/A000057). It's the right size to be easy to work with, has the latest hardware and is still pretty cheap. Official Arduino hardware is the best way to go IMO, you'd be saving at most $10 if you go with a cheap clone with the risk of getting worse quality components on the board.

fed0ra
08-22-2014, 07:55 AM
Definitely don't buy the bootleg stuff if thats what you are planning on (no link so I'm not sure); you don't want some cheap chinese electronics to catch fire in your car or fry your components. Arduino is cheap, cheap enough to not need to purchase knockoffs. Go to adafruit.com (that's where I bought mine...was gonna get it off of Amazon but apparently its hit or miss in terms of getting authentic boards) and pick out your board. You can also buy wires, soldering equipment, prototyping boards, etc., pretty much whatever you need.

ricekikr
08-22-2014, 08:03 AM
Lol. Forgot to paste the link. Knockoff from HK.

Arduino R3 (http://www.adafruit.com/products/50). Will this work? Basically just need it to output to a relay/switch based on three 5v inputs.

fed0ra
08-22-2014, 08:12 AM
Lol. Forgot to paste the link. Knockoff from HK.

Arduino R3 (http://www.adafruit.com/products/50). Will this work? Basically just need it to output to a relay/switch based on three 5v inputs.

That should work just fine. Thats the basic Arduino; when most people say "I have an arduino" this is the one they are referring to. It will be easy to learn on (pretty much every guide or tutorial out there is based on this board) and should be able to take care of what you need.

I actually just ordered a Mega from them. The displays I want to use apparently require 1K of ram each so they can fully buffer and the standard one only has 1K. Damn OLEDs...

Poopie
08-22-2014, 08:27 AM
the uno has a lot of documentation. This is really a "development"board. Its set up to a very broad range of tasks. Once you get past the development stage and want something more final, the actual micro controller chip is like $2. There is also a lot of documentation.

Micros are fun. Once you get the basics down, you'll find many more uses for them.

Poopie
08-22-2014, 08:28 AM
you can pic up these kits at Radio shack as well. There are a bunch of "shields" that you can buy too, which are just add on modules.

Mad Cow
08-22-2014, 08:29 AM
Lol. Forgot to paste the link. Knockoff from HK.

Arduino R3 (http://www.adafruit.com/products/50). Will this work? Basically just need it to output to a relay/switch based on three 5v inputs.

It'll work, but still I'd recommend the Leonardo since it's basically a newer version of the Uno for the same price.

fed0ra
08-22-2014, 08:42 AM
It'll work, but still I'd recommend the Leonardo since it's basically a newer version of the Uno for the same price.

For someone who has never used a microcontroller the Uno is easier to use. Besides, I don't think there is much added benefit with the Leonardo besides the USB functionality that it adds. I don't think he'll need that though so the simplicity of the Uno may be better for him.

ricekikr
08-22-2014, 08:46 AM
It'll work, but still I'd recommend the Leonardo since it's basically a newer version of the Uno for the same price.

Any 5v solid state relay would work? I just need it to disconnect the ground of the boost solenoid. Also it wouldn't matter what's being switched right? Ie 5v relay to switch a 12v boost solenoid ground, which should be about 1a max.

I remember asking about this on the Arduino forums before. But couldn't get a straight answer.

Poopie
08-22-2014, 09:01 AM
you need a relay that will draw less than 40mA. That is the draw limit on the digital pins for controlling on/off outputs. it would be wise to use a NPN transistor since you are trying to control the low side of the solenoid. You just building a failsafe?

you could get away with a solid state relay with an "on state" resistance of less than 125 mOhms.

ricekikr
08-22-2014, 09:19 AM
you need a relay that will draw less than 40mA. That is the draw limit on the digital pins for controlling on/off outputs. it would be wise to use a NPN transistor since you are trying to control the low side of the solenoid. You just building a failsafe?

you could get away with a solid state relay with an "on state" resistance of less than 125 mOhms.

Yup just a failsafe, for peace of mind when driving with eyes on the road.

I was also thinking of just using the i/o of my piggy back, but not sure how much ma and resistance it can handle. But it should be exactly the same as any 0-5v sensor.

Bikeboy7890
08-22-2014, 09:26 AM
There are some arduino compatible boards that are actually fine. The thing about the arduino is that it is open source, which means they post the schematics and anyone can make AND sell them based off the design without even paying royalties to arduino. Though it is nice to support the original board, if you NEED cheaper, you can get a defeatured board from other manufacturers. One example is the Evil Mad Scientist Diavolino (http://www.evilmadscientist.com/2010/diavolino/). This board is cheaper, but it doesn't include any of the jacks or headers, nor does it have a USB chip on board, you would have to purchase a FTDI USB-TTL cable (http://www.adafruit.com/products/954), that would work. It is $11.95, and the cable is another $9.95. The only thing is, is that you would only need one cable for as many boards as you use.

I am not trying to say get this board over the Uno or the Leonardo, only that with the world of open source hardware, there are some companies making cheaper boards that don't necessarily mean worse quality, just fewer on board things that you may/may not need.

Also, as long as the relay is rated for the voltage/current you are putting through it, then no, it doesn't care what power level is on each side of it. As long as you stay within its swithing frequency range as well. A logic level transistor could theoretically also do what you want, as well. Though a relay is probably more appropriate for your application.

Can I just say that I am so glad there is a community of guys on this forum who are interested in this world of electronics as well? I do agree with Poopie though, most people don't realize that the Arduino is supposed to really be a hybrid development board (IMO). It is designed to easily prototype with, and is very useful for creating many different projects with, but once you get it working, it is better to just get the chip with the bootloader on it (or not) and use that in a PCB based circuit so as to not have to have Arduinos all over the place.

ricekikr
08-22-2014, 09:36 AM
Also, as long as the relay is rated for the voltage/current you are putting through it, then no, it doesn't care what power level is on each side of it. As long as you stay within its swithing frequency range as well. A logic level transistor could theoretically also do what you want, as well. Though a relay is probably more appropriate for your application.


Oh good. Thanks.

fed0ra
08-22-2014, 10:30 AM
So, after doing a lot of research on using the Arduino to read from a wideband O2 and realizing that I can't just use the secondary O2 plug without some major modification (no pump circuit wire in a narrowband sensor, there may also be differences in the feedback loop of the heater circuit) I think this is the best option for anyone wanting to use the Arduino (or any other MC) to measure/display/log AFR from a wideband sensor: http://www.14point7.com/products/slc-oem

Its a PCB that is a full wideband controller that uses the Bosch LSU 4.2 sensors (the VW/Audi OEM wideband sensor). Basically you have to provide it a 5V power source and the O2 input and it gives you both a wideband output as well as a simulated narrowband input. The question I have, given all of this, is would I be able to have Dave at Motoza code out my heater circuit codes for the secondary O2? I'm assuming I can't just resistor them out since the voltage should be variable. My plan, currently, would be to run two wires (narrowband signal and ground) from the SLC board to a modified narrowband connector that only has those two wires; that way the car still gets its signal but doesn't deal with the heater. With resistors (maybe) or coded out heater (more likely) should I run into any problems?

ricekikr
08-22-2014, 11:28 AM
I was looking at the 3.2 displays. How much harder would it be to program the 3.2 vs the 2-liner display? Would the programming for the 2-liner work (albeit just two lines on a 240x320 display)?

Bikeboy7890
08-22-2014, 11:34 AM
I was looking at the 3.2 displays. How much harder would it be to program the 3.2 vs the 2-liner display? Would the programming for the 2-liner work (albeit just two lines on a 240x320 display)?

I THINK that they are more complicated than the HD44780 character displays (the 2x16 and all other displays in that family). The 3.2" display would also be much more taxing on an arduino based system as they require a considerable amount of display buffer memory. I am not sure on this though. I am pretty sure that they are not compatible with the character display programming.

fed0ra
08-22-2014, 11:44 AM
I THINK that they are more complicated than the HD44780 character displays (the 2x16 and all other displays in that family). The 3.2" display would also be much more taxing on an arduino based system as they require a considerable amount of display buffer memory. I am not sure on this though. I am pretty sure that they are not compatible with the character display programming.

The OLED display that I bought is monochrome and is something like 1"x1.3" and can display images. It requires 1K memory per display to buffer the entire thing, which requires something more than an Uno (hence me getting a Arduino Mega 2560). I have a feeling any other larger display would deal with the same issue.

ricekikr
08-22-2014, 08:13 PM
Was just about to order it. Thanks for the info. Will order the basic mega and go from there.

Bikeboy7890
08-22-2014, 10:41 PM
Was just about to order it. Thanks for the info. Will order the basic mega and go from there.

The mega will have enough RAM for the LCD. Be sure to share any progress you make with us!

ricekikr
08-23-2014, 06:19 AM
The mega will have enough RAM for the LCD. Be sure to share any progress you make with us!

Will do. Shopping for an ebay mega $13 lol. Just to see if I can even code it and see if it's reliable. Gona use it for non-safety stuff (sequential shift light) first.

Then try to write an afr failsafe or just use it to trigger the relays based on the signals from my piggyback (a diode will prevent any voltage from going back to my piggy and killing it right?).

Then maybe, a big maybe, as a pwm. I think the codes are already out there.

Bikeboy7890
08-26-2014, 06:22 AM
Just curious, any of you know where I can find info on the CAN system? Specifically as it relates to our cars?

fed0ra
08-26-2014, 07:27 AM
Just curious, any of you know where I can find info on the CAN system? Specifically as it relates to our cars?


Original Bosch CANbus spec sheet (http://www.bosch-semiconductors.de/media/pdf_1/canliteratur/can2spec.pdf)
Some general CANbus info (http://www.canbus.us/#Reading)

Mad Cow
08-26-2014, 10:49 AM
Original Bosch CANbus spec sheet (http://www.bosch-semiconductors.de/media/pdf_1/canliteratur/can2spec.pdf)
Some general CANbus info (http://www.canbus.us/#Reading)

Luckily we have the MCP2551 and MCP2515 now, they handle all the low-level stuff. But now that we're on the subject, is there any documentation about what PID means what? Is there any way to find out that doesn't involve sniffing canbus communications?

Mad Cow
01-17-2015, 03:39 PM
Some updates:
Now using a MPX5700DP (http://cache.freescale.com/files/sensors/doc/data_sheet/MPX5700.pdf) connected to the IM, by a pleasant surprise it can now read vacuum. It can't read anything lower than 7 in.Hg because of the response curve of the sensor, but it's good enough for now. Fixed the conversion formula too, turns out it was way off when I used the MAP sensor, it read something like 3-4 psi too high. Also implemented a smoothing library I found, much cleaner and more effective than my approach, though I will probably have to modify it to use more than 3 steps because that doesn't seem to be enough.

Here's a very terrible video of it in action:

http://www.youtube.com/watch?v=2Zxo4ho8EUg

Next step is to find a screen that doesn't suck and making the installation look decent.

The new code is in the first post, gonna add it to the github repo soon since it's ready for use at this point.

ricekikr
01-17-2015, 04:17 PM
Hows the response time? Accurate?

Been wanting to add this to my arduino. Just using it as a sequential shift light right now.

Mad Cow
01-17-2015, 04:43 PM
It's basically instant, even with 3 step smoothing you can see in the video it's probably quicker than a needle gauge. The datasheet says 1ms response time so the only limiting factor is the response time of the LCD, which is terrible. That's why I have the delay at the end. Running the code in a simulator the most I vacuum I can see is 9in.Hg, but that would be at 0v. 7 in.Hg is only a few steps higher so it makes sense. Now that I've looked into it a bit more my formula might be wrong once again, gonna look into it now.

EDIT: The formula's fine, it follows the datsheet spec. What's happening is I have the DP variation of the sensor, which measures differential pressure between 2 ports. It can't technically measure vacuum, but since 0kpa is supposed to output 0.2v anything below that it'll read a vacuum. So it's basically running outside of spec, it's not supposed to do that but my formula does not specify the 0.2v cutoff. I guess the proper way is still a 2-sensor approach, I was originally aiming for that but broke off one of the tiny SMD legs on the sensor I had and scrapped that idea for the time being.

ricekikr
01-17-2015, 05:22 PM
I meant the response time of the lcd. Guess it's slow. That's whats holding me back from making the boost gauge.

Could you expound more on the two sensor? I just checked my logs. The mxp6400 lowest value logged is .06v not sure how much vacuum that is.

Also checked the 6400 data sheet min is the same 6inhg. Edited above post.

Mad Cow
01-17-2015, 06:23 PM
The LCD is slow, but it's fast enough for the application, I'm looking into getting an OLED display which should fare better. I'm using the MPX5700, the min value is 0 kpa. The mpx6400 datasheet says min pressure is 20 kpa, where do you see 6 in.Hg?

My 2 sensor idea is to use an absolute pressure sensor connected to the IM and a barometric pressure sensor. You take the absolute pressure inside the intake system and subtract barometric pressure. That should give you a full range of vacuum and boost values, you just need a sensor that can handle an extra 100-ish kpa on top of your max possible boost reading.

ricekikr
01-17-2015, 08:40 PM
Ahh get it now.

Just used google to convert kpa to inhg. Checked it again and the calculation seems wrong? Operating pressure of 6400 is 3-58psi. I assume this its psia. 3psia = ~24inhg

Used this chart to conver psia to inhg
http://www.anver.com/document/company/Reference%20Guides/vacuum.html

Mad Cow
01-18-2015, 09:05 AM
Your MPX6400 and my MPX5700 aren't comparable since the 6400 measures absolute pressure and my 5700 measures differential (gauge) pressure. In your case you could add a barometric pressure sensor (or for the time being assume 100 kpa of pressure in your calculations) and you'll get a proper vacuum reading. I can't do that because mine already takes atmospheric pressure into account and it can't technically read any lower than 0 kpa.