Jump to content

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


zitronen

Recommended Posts

Hi Everyone,

A big thanks to zitronen for developing the demo code & plugin as well as thanks to everyone else who has posted in this thread.

It has been most helpful and has answered all of my questions up to now.

Ordinarily I'd just keep at it, but I have other things that demand my attention (family/education) and I want to get this working so that I can move on to the fun stuff :)

So far I managed to get all the basics going, the 3 basic lights and some switches.

That much I understand, but I'm stuck on the MAX7219 8 Digit 7 Segment Display code.

I added the library & defined my pins at the beginning of the KSPIODemo10 tab. Not sure if that's the place to do it, but I'm a total novice with this stuff & seems to work.

[INDENT]
#include <LedControl.h>
[/INDENT]



#define LEDClkPin 11

#define LEDChipSel 10

#define LEDDatain 12


LedControl lc=LedControl(LEDDatain,LEDClkPin,LEDChipSel,2);//1==num of 8x8pixel arrays in line. can be up to 8.

My guess is that I need to disable some other functions that want to use pins 10, 11 & 12

But when I added // to skip the existing lines the sketch threw up errors on another tab.

I used the following Void Loop() code as Mulbin seemed to have some luck with it after correcting a wiring error:

Replace the example numbers in the sketch with flight data
:)

Badly typed example:

void loop()

{

input();

output();

printNumLED(0, (long)(VData.Alt/100), ' ',2);//will print the altimeter with 2 decimal places (i.e. 12345.67 metres)

printNumLED(0, (long)(VData.AP/1000), 'A',3);//will print the apoapsis as kilometers, with 3 dp (i.e. 'A 96.321' km)


}//end loop

//note: adding things into mainloop is not the best, but makes for quick examples.

I also included the "LedControlFunctions" tab from AmeliaEatyaheart's sketch and it sort of works, displaying 0000 on the right hand side and seems to handshake with the plugin, but the numbers don't change.

Do I need to add another bit of code to the void setup(), or am I in for some editing to get the pins to do what I want?

Sorry if I'm missing something obvious, but my only code experience is VB Script in Excel.

Link to comment
Share on other sites

Um I think Mulbin would be the one to help you, since he has basically asked all the questions. See if you can PM him and get his working code.
I'll dig out my code later and share it, can't remember off the top of my head!

Thanks guys,

I eagerly (but not too eagerly, as I know you have things to do) await your response.

My project initially started out as a physical keyboard hack, but came undone when I accidentally ripped the trace off the USB board.

Then I found a cheap Arduino Uno & this thread :)

Added A Gif of my display troubles.

This is what happens with AmeliaEatyaheart's in the Void Loop after loading the sketch or pressing the reset switch.

8segLed.gif

When I place the same code in Void Setup, the Numbers are Static eg: A 0.000

I did get the Altimeter working with a regular 16*2 LCD panel, but this has me scratching my head.

Edited by T.A.P.O.R.
Link to comment
Share on other sites

  • 2 weeks later...

Hi guys,

I have merged my Cross Platform code-base with 0.17.1 upstream, so there is a testable Mac / Linux binary now up at

https://github.com/unixunion/KSPSerialIO/tree/master/release/0.17.1

I have only done the most basic of tests since my control panel is still under construction. If someone wants to test some of the new features on Mac or Linux.

Link to comment
Share on other sites

@T.A.P.O.R. Setup is only run once. Anything that should change needs to be in the Void Loop(), which is run over and over continuously while the Arduino receives power.

Thanks Freshmeat,

While I didn't know that about the setup, the image comes from the loop.

It only runs once (per reset) then goes dark.

Link to comment
Share on other sites

If you post your sourcecode I'm pretty sure we can help

If you say so :)

There have been a few variations on this, but the result is pretty much the same.

I've called the Led Control Library and placed it at the very top of KSPIODemo10

#include <LedControl.h>

//Test sketch for MAX7219 module 7 segment displays.


#include <LedControl.h>


#define LEDClkPin 11
#define LEDChipSel 10
#define LEDDatain 12


LedControl lc=LedControl(LEDDatain,LEDClkPin,LEDChipSel,12);

The only other changes I made were in the setup & loop and including the LedControlFunctions tab from this post



void setup()

[INDENT]{[/INDENT]


[INDENT=2] Serial.begin(38400);
blankLEDscreens();[/INDENT]

[INDENT]}[/INDENT]




void loop()

[INDENT]{
[/INDENT]


[INDENT=2]input();
output(); [/INDENT]
[INDENT=2]printNumLED(0, (long)(VData.Alt/100), 'A',2);[/INDENT]
[INDENT=2]printNumLED(1, (long)(VData.AP/1000), 'B',3);[/INDENT]

[INDENT]}[/INDENT]


Link to comment
Share on other sites

Hey zitronen, sorry I threw a bunch of code your way and then disappeared. :) Life got in the way there for a while.

Hey Stibbons, your fork still seems to be using

ActiveVessel.Autopilot.SAS.ManualOverride(true);

I'm trying to figure out what you did to change over to the new 0.90 autopilot stuff. I see you added some more options to the settings and rover stuff, so that's cool.

You're right, I didn't have a full understanding of how the new autopilot code is supposed to work. I did update the callback handler the plugin was using to the new 0.90 input chain, but that's minor at best. Glad you liked the other changes enough to merge them though!

Integrated new axes WheelSteer and WheelThrottle using code from Stibbons, now you can drive your rovers from your control panel!

AND IT IS AWESOME.

(ignore the forward/reverse directions being back to front in that video, it's what happens when you install the probe core in your unmanned rover upside down :( )

In other news @Zitronen, the config.xml file has ThrottleEnable set to 2, which seems to require a "throttle-off" ("x" key) upon launch, in order to make the hardware throttle actually able to put the throttle in game to zero. Without the "x" the game throttle simply jumps back to the 50% that it was at launch when the hardware throttle goes to zero. I've changed the ThrottleEnable to 1, which seems to work better.

The new options are great for the other axes (and I love that zitronen's set defaults that work for most use cases). But I don't think they're ideal for the throttle. I agree that setting it to 1 is usually the best option if you have a hardware throttle. 1 is identical to the old enabled option - the plugin will always use the value sent by the arduino, and ignore keyboard input.

My use case for the new options is the same pair of sticks that are in the above video. For general flight I use a USB joystick for rotation control, which has a little digital hat for translation. During docking maneuvres I use the sticks on my controller for translational control, but at the flip of a conveniently-located switch they can make rotational changes instead. I've docked with that setup a couple times, and it's also pretty awesome.

Edited by stibbons
Link to comment
Share on other sites

Hi everyone, it's my first post here. I'm making a control panel made of 2 arduinos, lcd, 2 sets of 8x7 segment displays, switches and propably 2 joysticks. The reason I need 2 arduinos is that the displays alone take up all pins on one arduino. Zitronen already suggested me to buy Mega, but right now I don't have funds for it and it will be a good prooving ground for me :D. I figured out the comunication between arduinos with SoftSerial and EasyTransfer, but it seems somewhat laggy. I forward every packet of VData to the second arduino but it looks like it's loosing sometimes even half a second of data. Does anyone know a way to help me? Maybe EasyTransferI2C will work faster? Any help will be appretiated. And Zitronen, thanks again for fast replies and an awesome plugin, you're the boss :D

Link to comment
Share on other sites

How are using a stage shift like a SX1509 for adding more pins to your Arduino over i2c?

There are plenty of expansion IO options from spark fun for cheaper than a MEGA.

Hi everyone, it's my first post here. I'm making a control panel made of 2 arduinos, lcd, 2 sets of 8x7 segment displays, switches and propably 2 joysticks. The reason I need 2 arduinos is that the displays alone take up all pins on one arduino. Zitronen already suggested me to buy Mega, but right now I don't have funds for it and it will be a good prooving ground for me :D. I figured out the comunication between arduinos with SoftSerial and EasyTransfer, but it seems somewhat laggy. I forward every packet of VData to the second arduino but it looks like it's loosing sometimes even half a second of data. Does anyone know a way to help me? Maybe EasyTransferI2C will work faster? Any help will be appretiated. And Zitronen, thanks again for fast replies and an awesome plugin, you're the boss :D
Link to comment
Share on other sites

@Psycho80: You can use really cheap ICs 74HC595 or 74HCT595 to expand your output ports. They are addressable over SPI and you'll need only a fixed number of pins (4 for output-only) on your arduino, no matter now many ICs you're addressing. Each 74595 will add eight output pins and you can chain them together.

I'm using 6 of them chained together to give me 48 outputs to drive 37 7-segment displays and 30 standard-LEDs in my work-in-progress controller. Soon I'll add another two 74595s for another 10 LEDs. All that requires 4 pins on the microcontroller. There's a schematic in the thread linked in my footer.

Note that the 74595 provides only outputs. If you need inputs the 74HC165 is your friend. It works pretty much like the 74595 but provides 8 inputs per chip. And yes you can chain the 165s and the 595 together pretty much endlessly, requiring a fixed 5 pins (you need one more for the input line, which you don't need for output-only operation).

Link to comment
Share on other sites

hardware SPI is orders of magnitude faster, I remember 400kbps or something, but I might be wrong

Oh and about the money: A 74595 costs around 30 cents in a local shop, much less if you order online. buy one and see what it does for you.

Link to comment
Share on other sites

Thanks for the replies, I might try that when I'll have money, but I'm trying to work it out with what I've got. Do you think that hardware I2C would work faster than software serial?

Yes it probably will. Make sure you are using the "fast" 400kHz ic2 speed. SPI is faster, but I don't know if there's an easy to use library for sending data structures.

Link to comment
Share on other sites

SPI sends one byte at a time by definition of the protocol but as usual you can make up your own "protocol" (big word for that) quite easily if you know what comes when. the KSPSerialIO communication between KSP and the microcontroller itself isn't much else tbh.

Link to comment
Share on other sites

The problem is, no matter what I try, single Uno is not enough for my configuration. LCD, 7 segment module on TM1638 and 7segment module on 73HC595 take up 12 lines of IO, and I need at least 7 or more of analog inputs, so I have two options, buying Mega, which will be possible in a month or so, or using two arduinos. I hope to figure out the "dual arduino" thing before I get to buy Mega because I dont like to abandon an idea before I do everything I can, so I'm open for suggestions.

Link to comment
Share on other sites

Stop using softserial for comms between your arduino. It's slow, and the UART emulation is expensive and unnecessary.

Try out SPI. I've never tried it between two arduinos myself, but seems easy enough. You should get much faster data transfer without unduly burning CPU cycles.

Link to comment
Share on other sites

The problem is, no matter what I try, single Uno is not enough for my configuration. LCD, 7 segment module on TM1638 and 7segment module on 73HC595 take up 12 lines of IO, and I need at least 7 or more of analog inputs, so I have two options, buying Mega, which will be possible in a month or so, or using two arduinos. I hope to figure out the "dual arduino" thing before I get to buy Mega because I dont like to abandon an idea before I do everything I can, so I'm open for suggestions.

I think you still have a few options here.

First, you could ditch the TM1638 - although I see its charm - and chain all 7 segments and LEDs over SPI. 5 pins total, plus whatever is needed to run the LCD.

Second, there are analog-to-digital converter chips which are addressable over SPI. That way you'd get ADC without using more pins. The MCP3208 is one example that gives you 8 analogue pins over SPI. But then I don't think the analogue pins are your problem?

Third, I mentioned this already, if you need more digital inputs, the 74165 family of chips gives you those, over SPI. Again, no additional pins required once you have SPI set up.

Fourth, I really like the idea of communication between Arduinos and it will be possible if you have the pins for the rest. That said you could perfectly well ditch the idea of having the 2 arduinos talk to each other and run them independently. Sure, KSP can only talk to one of them but you can make the other one be recognized as an USB joystick using VUSB: http://www.obdev.at/products/vusb/index.html - I've done exactly that and have a single microcontroller run 6 analogue axis and something in the order of 60 buttons. My computer thinks its a joystick/keyboard combo-device. You'll actually find my code in the VUSB forums. KSP has no idea that microcontroller even exists - the one "my" KSP talks to only handles a few buttons through a R2R ladder config and lots and lots of outputs. If you click the link in my footer I hope my initial post does a decent job of describing my approach.

All that said, I really hope you find a way to pull this off. It'd be awesome. Free those pins! :D

Link to comment
Share on other sites

what i like to do is union my structure with a byte array, so that anything you put in there is instantly serialized for you.

the library for either protocol (serial too, software or otherwise) will provide functions to allow you to transmit or receive any byte array, usually with just a pointer and a size. you might have endianness issues if going between an avr and a pc though (so on one end or the other you will need to do a lot of shifting oring and masking).

also now there are a number of very cheap wireless modules such as ESP8266 (wifi), and nrf24l01+ (ism) you can also use. former is serial and latter is spi. great little devices and you can get them under $5 each.

also skip the mega and get the due, its faster (80 mhz), and also 32 bit. i haven't used mine yet but it has an impressive spec sheet. 8 bit micros are going out soon.

Link to comment
Share on other sites

what i like to do is union my structure with a byte array, so that anything you put in there is instantly serialized for you.

the library for either protocol (serial too, software or otherwise) will provide functions to allow you to transmit or receive any byte array, usually with just a pointer and a size. you might have endianness issues if going between an avr and a pc though (so on one end or the other you will need to do a lot of shifting oring and masking).

also now there are a number of very cheap wireless modules such as ESP8266 (wifi), and nrf24l01+ (ism) you can also use. former is serial and latter is spi. great little devices and you can get them under $5 each.

also skip the mega and get the due, its faster (80 mhz), and also 32 bit. i haven't used mine yet but it has an impressive spec sheet. 8 bit micros are going out soon.

Be careful if you are going 32bit: http://forum.kerbalspaceprogram.com/threads/66393-Hardware-Plugin-Arduino-based-physical-display-serial-port-io-tutorial-%2817-Dec%29?p=1544333&viewfull=1#post1544333

It's still not clear if the code will run properly without massive changes due to struct padding.

Link to comment
Share on other sites

Hey Folks!

I have released the 0.17.1-2 version of the Mac / Linux / Win Port of KSPSerialIO.

Link

Changelog:

* major cleanup and rebase

* merge with 0.17.1 upstream code

* fixed autodetection

Edited by marzubus
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...