Jump to content

Arduino stuff/ programing/so cheap


flyingbrick

Recommended Posts

  • 2 weeks later...
  • Replies 416
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

I have some questions for the wizards.

I am wanting to fiddle with the suspension control unit in my Audi wag, it runs an air system where suspension heights can be selected but at certain speed thresholds the control unit will adjust the height itself. I'm wanting to find a way to stop this so I can have a manual adjustment only option. 

The road speed is provided via the canbus and by a redundant direct wire into the control unit.

Is it possible to create a box (e.g. arduino) to intercept and modify the canbus road speed signal? (I would only be looking to switch between 2 options, either pass through or replace it with a fixed signal, say one that translates to 40kph). I'm guessing the direct wire could be disconnected based on what I have read so far.

dS53kdT.jpg

Chur

Link to comment
Share on other sites

Teensy 3.6 has dual canbus, so what that means is you can snip the canbus wires to the controller. connect 1 canbus to your controller and the other side back to your main bus. Then pass all the info  through the Teensy both ways. This way you can tell which direction the signals are coming from and isolate the controller data. You can allow all traffic from the height controller back to main bus so it still communicates as needed. Isolating just the controller will help you figure out what each byte means. When the speed info comes from the direction of ECU you can intercept it and modify the signal before passing it through. This project is a bit more complex than it sounds (do you know the canbus datarate? Packet ids?)

Some time initially with a scope would be handy unless you have this info on hand from the manual.

Its definitely doable but definitely a learning curve! 

I can write you a pass through sketch for teensy 3.6 that would get you started identifying can frames.

But it would be a learning exercise from there as decoding can frames is a bit like reading tea leaves haha.

  • Like 3
Link to comment
Share on other sites

Cheers for the info, very useful! The teensy sounds like a good unit.

Canbus datarate for the drivetrain (which this stuff is on) is 500kbps max, Convenience and Infotainment are 100kbps max.

I have dug out a few packet ID's so far from others sniffing them out, will keep snooping to see what I can find.

Link to comment
Share on other sites

You only need to know the can frame id that contains vehicle speed, and then which of the bytes contain speed.

As this is the only one that yku need to pick out to modify. Everything else you can just tell to pass straight on through as is.

Keep in mind that you also need a transciever on the teensy to interact with canbus. (Sounds stupid and it is)There is a dual can backpack board available for it if you google.

 

  • Like 1
Link to comment
Share on other sites

Cool, will keep researching the soft side before committing, I don't need to do it but it would be fun to suss out :) 

Found this earlier
#define SPEED 0x351
/*
351h 8 45 00 00 00 00 75 7B 10 100 1795 Geschwindigkeit speed

h351, Geschwindigkeit, 8 byte, 100ms 
- byte 0: h00 vorwaerts, h02 rueckwaerts 
- byte 1/2: Geschwindigkeit 
- byte 4/5: Wegstreckenimpuls 

which roughly translates to

h351, speed, 8 bytes, 100ms
- byte 0: h00 forward, h02 backward
- byte 1/2: speed
- byte 4/5: distance pulse

and also
ID 0x351. Speed is contained in Byte 2. Calculation is (Speed = (buf[2] * 256) + (buf[3]-1)) / 190; )

 

Link to comment
Share on other sites

^^^Thats pretty much everything you need! Just need to know which byte of the can frame is the ID, probably 7 if 0 is already info. 


In other news, read a really good tip to stop those infuriating situations where you use = instead of ==

If you mean to write:

if (engineSpeed == 7)

But you accidentally write:

if (engineSpeed = 7)

Then you're in the shit because it makes the Engine Speed 7. 

But if you swap the order of your variable and the constant:

if (7 == engineSpeed)

Then if you accidentally use

if (7 = engineSpeed)

 7 can never become your variable so the code doesnt show a positive result 100% of the time.

I have screwed myself over with this one, multiple times hahhaa.

  • Like 4
  • Thanks 1
Link to comment
Share on other sites

  • 1 month later...
Quote

avrdude: ser_open(): can't set com-state for "\\.\COM4"

An error occurred while uploading the sketch

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

 

What does this mean?  Did i fry it again?

 

Link to comment
Share on other sites

COM 4 wasn't responding, i re-installed the drivers and plugged it into a different serial port and it started responding again as COM 5.  Stupidly forgot to test which fix it was.
I'll just guess a cooked my USB port by plugging it in while the car was running.

 

Beats me why this doesn't flash at 20ms intervals

 

 


void setup() {

 

  pinMode(LED_BUILTIN, OUTPUT);
}

void HighOut(uint8_t outPin)
{
  delay(20);
}

void loop() {
  digitalWrite(LED_BUILTIN, LOW);
  delay(1500);
  digitalWrite(LED_BUILTIN, HighOut);
  delay(250);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  digitalWrite(LED_BUILTIN, HighOut);
  delay(250);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  digitalWrite(LED_BUILTIN, HighOut);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  digitalWrite(LED_BUILTIN, HighOut);
  delay(250);
  digitalWrite(LED_BUILTIN, LOW);
  delay(1500);
  digitalWrite(LED_BUILTIN, HighOut);
  delay(250);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  digitalWrite(LED_BUILTIN, HighOut);
  delay(250);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  digitalWrite(LED_BUILTIN, HighOut);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(1500);
  digitalWrite(LED_BUILTIN, HighOut);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  digitalWrite(LED_BUILTIN, HighOut);
  delay(250);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  digitalWrite(LED_BUILTIN, HighOut);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  digitalWrite(LED_BUILTIN, HighOut);
  delay(250);
  digitalWrite(LED_BUILTIN, LOW);
  delay(1500);
  digitalWrite(LED_BUILTIN, HighOut);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  digitalWrite(LED_BUILTIN, HighOut);
  delay(250);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  digitalWrite(LED_BUILTIN, HighOut);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(2500);
  digitalWrite(LED_BUILTIN, HighOut);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  digitalWrite(LED_BUILTIN, HighOut);
  delay(250);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  digitalWrite(LED_BUILTIN, HighOut);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  digitalWrite(LED_BUILTIN, HighOut);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(1500);
  digitalWrite(LED_BUILTIN, HighOut);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  digitalWrite(LED_BUILTIN, HighOut);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  digitalWrite(LED_BUILTIN, HighOut);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(1500);
  digitalWrite(LED_BUILTIN, HighOut);
  delay(250);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  digitalWrite(LED_BUILTIN, HighOut);
  delay(250);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  digitalWrite(LED_BUILTIN, HighOut);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(2500);
  digitalWrite(LED_BUILTIN, HighOut);
  delay(250);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  digitalWrite(LED_BUILTIN, HighOut);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  digitalWrite(LED_BUILTIN, HighOut);
  delay(250);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  digitalWrite(LED_BUILTIN, HighOut);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  digitalWrite(LED_BUILTIN, HighOut);
  delay(250);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  digitalWrite(LED_BUILTIN, HighOut);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(5000);
}

Link to comment
Share on other sites

One thing which has been a ball buster until i realised why. Any program that scans the com ports looking for a device fucks with any others doing the same. If i have arduino ide open i cant connect on pclink. And vice versa. Took a while to figure that out...

  • Like 1
Link to comment
Share on other sites

Something else ive figured out recently while trying to make a trip meter.

I got caught up thinking that to convert hours into a smaller number you need to go minutes then seconds... but this is a problem because you need to divide by 60 so you get a remainder on your number that gets wiped so its less accurate when you're dicing up 50kph into 10hz snippets (or whatever)

Instead of that.  Figured out i could just use interrupts at 1000th of an hour (or whatever) so the value you end up with is only ever divided or multiplied by 10.

So for example 50kph you might set your interrupt frequency so you get a number back saying you travelled 50cm in that time. Makes the maths super easy!

Kinda like a metric version of time keeping haha.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...