Jump to content

[Hardware, Plugin] Arduino based physical display + serial port io+ tutorial (24-11-19)


zitronen

Recommended Posts

OK from you logs it seems like everything is working. Can you just make sure your rocket can actually exceed 5G to turn on the yellow led and 9G to turn on red led? Obviously you can also change the limits in the arduino code.

Link to comment
Share on other sites

OK from you logs it seems like everything is working. Can you just make sure your rocket can actually exceed 5G to turn on the yellow led and 9G to turn on red led? Obviously you can also change the limits in the arduino code.

It works! Haha, I feel really stupid now. I assumed that the code would work if my fuel ran out, and that is how I was trying to trigger the red and yellow LED. I will get an LCD display sometime this week, so I will be able to test the values for the fuel and see why it was not triggering the LEDs.

Thank you very much! :D this made my day. So excited to put it together.

Link to comment
Share on other sites

It might be somewhere in the thread, but I did not take the time to scan all 50+ pages...Do you have any info on compatibility with the Teensy? In most cases it seems to be totally compatible with Arduino code, but sometimes (like this) there seem to be minor issues.

Looks like I get initial connectivity as the launch pad loads, I get the 'starting' and 'using' messages for the correct serial port, and the green LED will light during load. After that, no LEDs and I do not seem to get data on my LED-Displays. I have used the same code and connections on an Uno and it works fine, but I am planning on running a lot of peripherals that I think will more than max out the UNO and even a MEGA in terms of computing power...I am guessing the problem stems from the memory and buffer manipulation in the SerialCOMS section and I am going to experiment with the hopes of fixing it, but I figured I would see if you had any existing info first.

Link to comment
Share on other sites

It might be somewhere in the thread, but I did not take the time to scan all 50+ pages...Do you have any info on compatibility with the Teensy? In most cases it seems to be totally compatible with Arduino code, but sometimes (like this) there seem to be minor issues.

Looks like I get initial connectivity as the launch pad loads, I get the 'starting' and 'using' messages for the correct serial port, and the green LED will light during load. After that, no LEDs and I do not seem to get data on my LED-Displays. I have used the same code and connections on an Uno and it works fine, but I am planning on running a lot of peripherals that I think will more than max out the UNO and even a MEGA in terms of computing power...I am guessing the problem stems from the memory and buffer manipulation in the SerialCOMS section and I am going to experiment with the hopes of fixing it, but I figured I would see if you had any existing info first.

Hmmm... I haven't used a Teensy myself but the communication between the game and the microcontroller is standard serial with a "custom" protocol if you want to call it that. I don't see why what wouldn't work with a Teensy.

Just had a quick look at some more details of a Teensy - if you're using a Teensy 2.x then that seems to have an 8-bit Atmel chip on board. In that case my port of Zitronens Arduino code to AVR C probably run more or less right away: https://github.com/MrOnak/avr_KSPIO

The Teensy 3.x'ses seem to run on 32-bit ARM processors (holy crap)? My code probably won't work out-of-the-box there but I don't see why it wouldn't be portable on a rainy day like today :)

Link to comment
Share on other sites

The Teensy 3.x'ses seem to run on 32-bit ARM processors (holy crap)?

Haha, I know...The little things are monsters, especially at a ~$20 price tag...

I will have to check out your port in more detail if I can't get things to work straight from Zitronen's with only a little modification...Part of what I love about the Teensy is the fact that they made an add-on allowing normal use of the Arduino IDE to program them...Saved me a great deal of time (and allowed me to be lazy) not having to figure out winAVR and the coding differences.

If nothing else, I can probably just write the data parser over again from scratch (though I mine will be ugly and inefficient), but I am pretty sure all it will take is a little tweaking on the buffering and addressing to get it working. I was just curious about whether or not it had already been done by someone on here.

Link to comment
Share on other sites

Found where the problem is...I don't have time at the moment to figure out a fix though.

if(rx_len != structSize){

printNumber((int) rx_len);

delay(1000);

printNumber((int) structSize);

delay(1000);

rx_len = 0;

return false;

}

I added these lines into the SerialCOMS and found that rx_len is 177 and structSize is 180, so it does look like it is just a matter of matching up the bit lengths between the 8-bit and 32-bit architectures.

Link to comment
Share on other sites

If nothing else, I can probably just write the data parser over again from scratch (though I mine will be ugly and inefficient), but I am pretty sure all it will take is a little tweaking on the buffering and addressing to get it working. I was just curious about whether or not it had already been done by someone on here.

The whole parser is wrapped up in the kspio_boardReceiveData() function in here: https://github.com/MrOnak/avr_KSPIO/blob/master/kspio/kspio.c

This should be really easy to port.

The only "trouble" I had was to find an UART library that worked natively on an Atmel microcontroller but I asume the one used in my port will work on the Teensy OR you'll be able to use the one that comes with the Teensy flavor of the IDE.

In any case, good luck porting it and please report if you're successful. I'm actually very curious about Teensies now that I know they exist :D

Link to comment
Share on other sites

Hmm I don't know what could be the problem other than the obvious things like different pin layout. I don't really use any special arduino stuff. I worked on a Teensy 3.1 at work using the Arduino IDE, I'll see if I can test it. I'm off the a conference next week so will have to wait till next weekend.

Since it's got loads of serial pins you can use them to print some debug stuff out to a serial terminal I guess?

edit oops posted 10min too late to see your post.

Link to comment
Share on other sites

OK interesting, there are three "long"s in the struct. Maybe replacing them with int32_t?

Edit: Actually it could be a struct padding problem: http://vcfaq.mvps.org/lang/11.htm

Hmm...

OK so the solution might be to add gcc __attribute__ modifier:

 ...
float Heading; //45
} __attribute__ ((packed));

Edited by zitronen
Link to comment
Share on other sites

OK interesting, there are three "long"s in the struct. Maybe replacing them with int32_t?

Yeah, I have tried that too...Going to take a break from it for a while, because I must be missing something silly...Not sure how the sizeOf() something consisting of 3x int32_t's (12 bytes), 2x uint32_t's (8 bytes), 39x floats (156 bytes), plus and extra byte for the 'id' (12+8+156+1 = 177 last I checked) is being reported as 180 bytes...

Edit: Actually it could be a struct padding problem: http://vcfaq.mvps.org/lang/11.htm

Ahh...Good call...If it is padding that first byte holding the 'id', that would definitely explain the 3 byte difference...When I get back to it next time that will be where I start.

Link to comment
Share on other sites

Well, I found a solution...It is a bit ugly, but it looks like it will do the job...

What I did was strip out all of the checksum code, remove the rx_len to structSize comparison, re-order the struct of VesselData so that VData.id is that LAST byte, set VData.id=id rather than using the buffer, and drop the initial value of rx_array_inx from 1 to 0...

It definitely was the a padding issue and when I start adding in control outputs I am sure I will have to make the same hacks.

The gcc __attribute__ modifier you suggested is probably the more elegant (and correct) way to do things, but is something I am unfamiliar with in my playing around so far....Eventually I will go back and learn things the right way.

Link to comment
Share on other sites

What you are doing is probably faster. There's a good reason for the padding apart from just making people smash heads against tables :). Forcing it to not pad with the modifier will probably hurt performance, but makes your code neater. The next time I update the structure I will keep this in mind, I think I will just change the id to uint32.

Link to comment
Share on other sites

Also, I promised pics once I got them uploaded - I know photobucket's not the best, but it works :)

So, once again, thankyou zitronen, for this wonderful plugin! :D

http://i133.photobucket.com/albums/q80/LordPhobos6920/20140722_160355.jpg

http://i133.photobucket.com/albums/q80/LordPhobos6920/20140808_143325.jpg

http://i133.photobucket.com/albums/q80/LordPhobos6920/kerbal_panel_fuelgauges.jpg

Hey Amelia,

that's some nice work! :)

I'm currently in the process of building an arduino based control panel myself and i got some questions regarding yours.

I've ordered a couple of 5V meters and intended to drive them via rc-filtered PWM - is that how you did it? Also: Great inlays! How did you go about creating those curved scales?

Lastly i'd like to know where you got those rectangular illuminated pusbuttons. I've found some on ebay, but they seemed rather expensive.

You really should create a thread for your project and keep us informed, there are far too few about. I'm going to do that anyway once my ordered parts arrive and i can start building.

Link to comment
Share on other sites

Lastly i'd like to know where you got those rectangular illuminated pusbuttons. I've found some on ebay, but they seemed rather expensive.

Ah, illuminated pushbuttons... my nemesis. I found it extremely difficult to find good looking ones at a reasonable rate, too. Finally I settled on a small set that Adafruit has: http://www.adafruit.com/products/1479

They're available as momentary and latched varieties and in a few colors. They don't seem to be exactly those that Amelia used but it might be worth checking. Adafruit has global distributors, you should be able to get them from a local dealer if you're outside the US like I am. I ended up mailing them, they ordered them with their next batch from Adafruit and sent them to me at no extra charge.

Link to comment
Share on other sites

I can't promise quality, but I have always had good luck ordering from Aliexpress...Here is the best option I have found on there:

http://www.aliexpress.com/item/KD2-22-ON-ON-Momentary-illuminated-push-button-switch-RED-GREEN/2021412603.html

hard to go wrong with 20 for 10$ shipped, but I have no idea what the specs are as far as LED/incandescent lamps and voltage.

(Oh, and shipping to the US from China is anywhere from 2 weeks to a month, so that could play a factor...)

Personally, I am going to go with an RGB led mounted next to the switches that will change from red to green as the button is hit. This is a quick sketch-up of what I am going for:

http://imgur.com/5v70ZPi

Alt Display LED Displays for AP, PE, and ALT with time to AP and AE...I am going to make the ":" solid when displaying hours/minutes and flashing when displaying minutes/seconds

Velocity display: Since you have orbital, vertical, and surface velocity to track, I am going to have one display with buttons to change which is displayed, the current mode will be indicated by LED.

Fuel Gauge: I plan to use and LCD screen to show colored bars displaying things like fuel, oxidizer, electricity, etc...There will be a button and a pair of LEDs here as well allowing you to toggle the display from current stage to total levels.

Staging button and a read out of the stage number.

RGB Indicators: to indicate things like air density and G force, I will probably add some others to this later on.

Action Groups: each button with an RGB Led to indicate off/on in red/green

Throttle control: with leds colored along side going from green to red based on power.

Maneuver Nodes and the remaining delta v required...This will also display the mission time when there is no current node, and the button / led will toggle between them when there is.

Audible alarm with an alarm silence button and flashing LED

Panic/Abort of course.

Navigation system...I am not sure yet how I am going to handle this, but it will basically replace the nav ball somehow with another LCD.

I may or may not eventually and a pair of small joysticks to handle steering and RCS toggling...What I would REALLY love to do is find a small 4 - axis control stick that won't cost more than the rest of the project put together...I have found a couple nice ones on Aliexpress for around $30-40, but the shipping on them ends up bring the total to close to $100

Edited by harbingerx81
Link to comment
Share on other sites

Hey Amelia,

that's some nice work! :)

I'm currently in the process of building an arduino based control panel myself and i got some questions regarding yours.

I've ordered a couple of 5V meters and intended to drive them via rc-filtered PWM - is that how you did it? Also: Great inlays! How did you go about creating those curved scales?

Lastly i'd like to know where you got those rectangular illuminated pusbuttons. I've found some on ebay, but they seemed rather expensive.

You really should create a thread for your project and keep us informed, there are far too few about. I'm going to do that anyway once my ordered parts arrive and i can start building.

Thankyou very much, I'm rather flattered you like my work that much! :)

Again, thanks to zitronen for making this plugin - my panel would have only been a rough idea at best without that magic! :D

Some of my hardware is abismally simple - the 5V voltmeters I run are all driven direct from the Arduino's PWM lines, I didn't even bother with any filtering! They do 'jump' between PWM steps though, so filtering would likely help with that. I have to admit, I do like mine looking a bit dodgy like that though ;)

If you are going to build some filetering, keep in mind these voltmeters are usually just ammeters with an inbuilt resistor, so if you add another resistor you won't get full voltage swing. Play around with your multimeter and some caps and see what happens :)

Those rectangular push-buttons - honestly... ebay, ebay, ebay. The trick is bargain hunting, and don't be afraid to mess with the hardware.

Those buttons - some of them were 12V, 24V, and 220V, go figure! I got all momentary buttons, ripped the LEDs out, rewired them without the inbuilt resistors, then added external resistors so that I can adjust the brightness on my I2C board :) Any push-on-push-off action is purely done in code; I wanted all the buttons to be fixable if I wanted to change the action :)

As far as the curved inlays on the panels go - I'm assuming you mean the rescaled meters? I scanned in one of the original plates into my CAD program, and from that image, re-drew it from scratch - never mix old and new imagery unless you're that good. :)

And yea, Adafruit is an awesome resource for hobby / arduino gear - most of my parts either came from there or ebay :)

Edit: Decided to take up your suggestion and start my own hardware thread: http://forum.kerbalspaceprogram.com/threads/100977-Hardware-Custom-KSP-flight-panel-with-flight-computer

Edited by AmeliaEatyaheart
Link to comment
Share on other sites

With all my unasked questions already answered in this thread, I managed to get my LCD reading stuff within about 10 mins with modification to demo8.

I thought I better make an account and just say thanks. Throughout there seems to be a lot of things like people reporting that your code is broken only to find that they put a colon at the end of a line. Thanks for being patient with all us nubs zitronen.

Link to comment
Share on other sites

Well, I just spent 3 hours trying to figure out how to get my Teensy version to correct for the structure padding issue on KSPBoardSendData()...All sorts of different variable arrangements, complicated buffers trying to arrange things correctly to get the right checksum, ridiculous bitmath, reading serial data and trying to convert the ACSII output into hex...Many many things that had me pulling my hair out...

Then, the "eureka/you-stupid-...." moment finally came when I remembered that the Teensy has capabilities to do Serial + Joystick + Mouse + Keyboard emulation all at the same time, something I have never used...Less than a minute after this 'discovery', and one short line of code later (literally as simple as: Keyboard.print(" "); ), I launched with a hardware button and felt that all to familiar mix of accomplishment from solving the problem, and embarrassment that I did not think of the obvious sooner...

Link to comment
Share on other sites

the arduino leonardo can do that too. though getting the hid joystick to work takes a few modifications to the arduino libraries. i found a tutorial with a simplified example with 4 (8 bit) axes, 2 hats and 32 buttons. i didnt like it so changed the hid descriptor to support 8 (16-bit) axes instead. and it works great.

got me an ads1115 i2c adc breakout as well so i can make use of those large axis ranges. it can do 2 16-bit differential channels or 4 single ended 15-bit channels. it has a prescaler that makes things confusing, it doesnt quite measure across a 5v range like the 10-bit adcs on the arduino. you can set it to ranges of: 256, 515, 1024, 2048, 4096, 6114 (clipped at 5000, because exceeding 5v would kill it) milivolts. so i set it to the 4096mv range, and simply put a resistor on the 5v side of the pot, of 1/4 the resistance across the pot. this lets the pot only output a value between 0 and 4 volts, and the adc is happy with it, mapping it out to the full range.

if you wanted an extra bit of resolution, you have differential mode. it would require a 2v reference on one of the differential inputs, a voltage divider would work fine. the pot would be hooked up in about the same way as single ended mode. the prescaler would need to be set to 2048, since you are measuring in relation to the 2v reference, so +/- 2v. by playing with the reference voltage such as with another pot, you could do trim in hardware.

analog is fun.

Edited by Nuke
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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...