flyingbrick

Arduino stuff/ programing/so cheap

Recommended Posts

Oh, re the Arduino environment doesn't do autocomplete:

VisualMicro is an arduino extension for MS VisualStudio. 

Do try it.

 

 

  • Like 1

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Not the best way to do it, but I would set up a second CAN network just for that device. You could hook it into the main network too, as a pass-through for when you want to disable your special controller.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Depending on what thd redunfant speed wire signal is like you could most likely input that at a different speed also.

Pity you dont live closer as this sounds like a cool project to try figure out! 

  • Like 1

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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; )

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
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?

 

Share this post


Link to post
Share on other sites

Maybe. When you connect/disconnect the Arduino does 'Port' under the Tools menu display an extra COM port? (Make sure you collapse the menu to allow it to refresh its state)

Share this post


Link to post
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);
}

Share this post


Link to post
Share on other sites

That code isn't very nice to look at. You could do the same thing with about 10 lines. Also, why HighOut instead of HIGH?

Share this post


Link to post
Share on other sites

Hey rusty your highout function is not returning anything, what were you aiming for?

Share this post


Link to post
Share on other sites

Yeah, that shit no work. What trying to do?

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
13 hours ago, Ghostchips said:

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

  Hide contents

 

Perhaps because of the 43.8 seconds of delay statements in the main loop?

Share this post


Link to post
Share on other sites

I suggest you start with the example code called blink, and read the pages associated with each keyword/ library routine, i.e. "delay" and "digitalWrite". The answers are there.

  • Like 2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now