Jump to content

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


zitronen

Recommended Posts

The LCD is slow, therefore it works well with a communication baud rate of 9600, the arduino and computer are fast, so the use a very fast communication speed.

If you are going to communicate with the LCD using RS232 protocol (RX/TX) you need to use the RX-TX that the UNO uses to talk with the computer.. PAAAAM!!! You can't do that because it is already being used!

If you are using Arduino Mega (ATMega2560) then you can open a secondary RX/TX bus to communicate with the LCD.

the COM's are those serial communication ports which the arduino and the computer uses to communicate with each other, so if you want to setup the LCD to be used via RX/TX you will have trouble if you are not using the MEGA.

Link to comment
Share on other sites

Hey everyone. After few months VERY slow progress and strugle with KSPio and arduino, I am back here to show you some little of my work. KSP speedometer, "Retro" style. Do somebody like Nixie tubes? :D

No enclosure/control panel yet so its bit messy

2nl5m6h.jpg

In night it looks realy cool. Nixies are cool.

35jzccj.jpg

And here short after launch of "Energia-SPB2" (SuPer Booster so its bit slow on start :D )

fjkb6d.jpg

Its 100% custom build, drive code for arduino is from scratch (execpt of KSPio of course ;) )Right now I am working on code optimalisation (for faster processing and make switch between orbital speed and surface speed) and now i can focus on another parts of project.

Link to comment
Share on other sites

The LCD is slow, therefore it works well with a communication baud rate of 9600, the arduino and computer are fast, so the use a very fast communication speed.

If you are going to communicate with the LCD using RS232 protocol (RX/TX) you need to use the RX-TX that the UNO uses to talk with the computer.. PAAAAM!!! You can't do that because it is already being used!

If you are using Arduino Mega (ATMega2560) then you can open a secondary RX/TX bus to communicate with the LCD.

the COM's are those serial communication ports which the arduino and the computer uses to communicate with each other, so if you want to setup the LCD to be used via RX/TX you will have trouble if you are not using the MEGA.

Sorry for replying late.

That makes sense! O_O Thank you! I'll wait for the Mega before I work on the screen anymore. Thanks for explaining that! Now I Just have to be patient and wait. :P Guess I'll keep working on designs.

Link to comment
Share on other sites

...

SoftwareSerial lcd(3, 2); //LCD on pin 2

...

#define AGLight 2

#define AGGear 3

...

If I understand your code correctly you're trying to use pin 2 and 3 for SoftwareSerial but they are also defined as input pins in Zitronens code. That will probably get really messy I/O-wise.

Hope that helps a bit...

Link to comment
Share on other sites

Long time ago I used to draw and write at LCD's using a C library I made (and latter I found an exact copy online) to do an 8bits parallel control of large LCD displays. They are fine, and there are those that work with I2C comm that are a little bit better to use when doing arduino projects. The RXTX ones are nice if you want to control'em directly trought the PC or if you have enough COM's around :)

- - - Updated - - -

Hey everyone. After few months VERY slow progress and strugle with KSPio and arduino, I am back here to show you some little of my work. KSP speedometer, "Retro" style. Do somebody like Nixie tubes? :D

No enclosure/control panel yet so its bit messy

http://oi57.tinypic.com/2nl5m6h.jpg

In night it looks realy cool. Nixies are cool.

http://oi58.tinypic.com/35jzccj.jpg

And here short after launch of "Energia-SPB2" (SuPer Booster so its bit slow on start :D )

http://oi61.tinypic.com/fjkb6d.jpg

Its 100% custom build, drive code for arduino is from scratch (execpt of KSPio of course ;) )Right now I am working on code optimalisation (for faster processing and make switch between orbital speed and surface speed) and now i can focus on another parts of project.

C'mon! This is awesome! I never saw one of those working! These are the real vacum tubes or LED mockups?

Link to comment
Share on other sites

These are the real vacum tubes or LED mockups?
Yup, they are real. 170V power source needed :D Got them from old voltmeter many years back. Made in SSSR. Here in better light http://oi60.tinypic.com/o5yfld.jpg Two videos bonus. Short from space station in orbit http://tinypic.com/player.php?v=23h0qjp%3E&s=8#.VgBcU9_tlBf , second vid is launch of Saturn V http://tinypic.com/player.php?v=10nyznl%3E&s=8#.VgBdv9_tlBc Sound in background is little fan cooling switching transistor in 170V power supply.
Link to comment
Share on other sites

If I understand your code correctly you're trying to use pin 2 and 3 for SoftwareSerial but they are also defined as input pins in Zitronens code. That will probably get really messy I/O-wise.

Hope that helps a bit...

I'm no expert on this, but as I understand those are like a variable that KSP updates. It can be accessed as VData.(variable name here). Pin 2 and 3 weren't in use in the demo code, so I used them for the LCD. Like I said though, thats just what I got from poking around. I could be misunderstanding things. You said SerialSoftware? Does defining it there cause it to reserve a pin?

Also, thats a SWEET K-42 Console! I'm hoping to get my Mega to emulate keyboard commands at the same time as running KSP SerialIO, but I haven't done any research to see if I can. If not, I guess I'll get a Leonardo and run them side by side. :) I like the layout of your board though.

Link to comment
Share on other sites

Yup, they are real. 170V power source needed :D Got them from old voltmeter many years back. Made in SSSR. Here in better light http://oi60.tinypic.com/o5yfld.jpg Two videos bonus. Short from space station in orbit http://tinypic.com/player.php?v=23h0qjp%3E&s=8#.VgBcU9_tlBf , second vid is launch of Saturn V http://tinypic.com/player.php?v=10nyznl%3E&s=8#.VgBdv9_tlBc Sound in background is little fan cooling switching transistor in 170V power supply.

This is so awesome!

Anyway, I won't ever be doing this kind of thing because I hate to use dangerous voltages in my rigs (I'm a electronic technician that is afraid to death of electricity!!!!)

I made a movie showing my avionics working, but I don't have an internet good enough today to upload it to youtube.

Right now I'm trying to make something good with the avionics.

Link to comment
Share on other sites

I'm no expert on this, but as I understand those are like a variable that KSP updates. It can be accessed as VData.(variable name here). Pin 2 and 3 weren't in use in the demo code, so I used them for the LCD. Like I said though, thats just what I got from poking around. I could be misunderstanding things. You said SerialSoftware? Does defining it there cause it to reserve a pin?

Also, thats a SWEET K-42 Console! I'm hoping to get my Mega to emulate keyboard commands at the same time as running KSP SerialIO, but I haven't done any research to see if I can. If not, I guess I'll get a Leonardo and run them side by side. :) I like the layout of your board though.

Declaring av SoftwareSerial object will reserve both pins, even if you only use one of them for serial output. I recommend you don't try to redeclare any of them for other purposes even if you don't use serial input as it may (will?) cause strange things.

As for my K-42: Thank's a lot for the appreciation. I have the main code up and running and all 10 interconnected arduinos in the console works as planned. The problem I ran into the other day was that I've used up all RAM in the Arduino Pro Mini I use as master node when trying to implement the Guidance Computer functionality. I plan to get a Mega just for its larger memory capacity and use it to implement the guidance computer. I will probably keep the Mini as an output slave as it has better native support for emulating USB devices and also because that way I can keep much of the already tested and working code and use all memory in the Mega for guidance programs.

As for the layout, it is totally changeable. I can swap places of any modules as I please without reprogramming or resoldering. There is only a four wire bus for power and data that connects them and it can be extended with any type of wiring that can handle a modest 100kb/s, which should be any audio wire as long as they are reasonably limited in length. I actually have some plans to extend the system and build an overhead panel with some 7 segment displays I have laying around, and later on maybe build a couple of module enclosures on my chair arm rests and move joysticks and throttle modules to them. I just love modularity. If I ever get sufficient space and wife acceptance I will build a real simpit and mount my module inside it. :D

Link to comment
Share on other sites

Declaring av SoftwareSerial object will reserve both pins, even if you only use one of them for serial output. I recommend you don't try to redeclare any of them for other purposes even if you don't use serial input as it may (will?) cause strange things.

As for my K-42: Thank's a lot for the appreciation. I have the main code up and running and all 10 interconnected arduinos in the console works as planned. The problem I ran into the other day was that I've used up all RAM in the Arduino Pro Mini I use as master node when trying to implement the Guidance Computer functionality. I plan to get a Mega just for its larger memory capacity and use it to implement the guidance computer. I will probably keep the Mini as an output slave as it has better native support for emulating USB devices and also because that way I can keep much of the already tested and working code and use all memory in the Mega for guidance programs.

As for the layout, it is totally changeable. I can swap places of any modules as I please without reprogramming or resoldering. There is only a four wire bus for power and data that connects them and it can be extended with any type of wiring that can handle a modest 100kb/s, which should be any audio wire as long as they are reasonably limited in length. I actually have some plans to extend the system and build an overhead panel with some 7 segment displays I have laying around, and later on maybe build a couple of module enclosures on my chair arm rests and move joysticks and throttle modules to them. I just love modularity. If I ever get sufficient space and wife acceptance I will build a real simpit and mount my module inside it. :D

I see what you're talking about now! I hooked it up to my new Mega and remapped all the pins. Both the controls and the LCD screen are working now! Thanks for all the help. :D

Side note: While both are working, I have the Mission Time displayed on the LCD and I noticed that although it refreshes every 250ms, the variables update anywhere from 1s to 5s. Still, this doesn't effect controls or anything, so I'm leaving it for the time being. Just thought I'd mention it in case anyone has had this issue. :)

The guidance system sounds amazing. I read a bit about it from what you've posted here.

I'm going to attempt to make mine modular too, but I don't have that many arduinos, so it'll have to still be close. XD I envy that setup! Rock on!

Link to comment
Share on other sites

It isn't actually that expensive to buy the simpler arduinos if you buy clones from China. I bought the pro mini clones I use in my modules for $3 each from Banggood.com and it should be possible to get close to $2 if you accept longer delivery times, buy a larger batch (i but I bought five at a time) or spend some time looking for a bargain on several web stores. The Pro Micro cost three times as much, need only one 32u4 to emulate all USB devices. The total cost for all arduinos was less than $40 and I still have one left over.

Link to comment
Share on other sites

Finally took some time this evening to understand a little bit more about C# and how the serial event stuff is working. Or, you know, isn't working.

Have you tried contacting Marzubus? I think he had the same event issue on Mac/Linux. Maybe he knows the cause of it.

Marzubus had the same problem with the Port.ReceivedEvent not being fired, and solved it in exactly the same way. No seriously, exactly the same way. Compare Zalta's use of MonoBehaviour.Update() here with Marzubus' implementation here.

The best recommendation so far was to use a faster serial baud rate, which is supposed to minimise the time spent in Update(). In the same vein, I suspect that making sure the Arduino's TX buffer is big enough to send the control packet all at once will help make sure the receiving is processed in a timely fashion.

I'm keen to start experimenting with moving the serial check out of Update() and having a coroutine execute it periodically. That's still less elegant than getting an event from the serial port, but hopefully less of a burden.

- - - Updated - - -

I don't have framerate issues, but my PC is verry powerfull.

As said Zitronen, removing the event is not a pretty solution, because we force the plugin to work everytime, and it's bad.

I have delays problem with my code, the response time is something like .1 or .2 seconds.

I think I'm going to give up, and install Windows 7 in dual-boot.

Again, moving the serial polling out to a coroutine still isn't as great as the event, but less ugly than polling every frame.

There's a handful of different issues that can contribute to long delays:

* The code in your github repository still has a lot of debug stuff in it, it's logging info from the port in every update, which can't be helping performance. :)

* zitronen's KSPSerialIO distribution sets a default refresh rate in the configuration file of every 0.2 of a second, so you're already only seeing five updates per second at the best of times.

* If you're using Marzubus' cross-platform KSPSerialIO distribution, no default refresh rate is specified; it will try to send a VData packet in every Update(), both killing KSP performance and swamping the arduino code.

* The small serial buffer in the Arduino can mean that a lot of VData packets coming in are corrupted, slowing how often it's able to update.

* Faster baud rates mean the Arduino has to poll for new data more frequently. Combined with the small serial buffer this can mean almost no VData packets are successfully received.

I'm getting the feeling that the big complex controller projects that are coming up here more often (including mine, I have to admit :D ), combined with relatively inefficient Arduino libraries, are really starting to push the limits of what little 8-bit microcontrollers are capable of. And now with obscure callback failures in mono/Unity, the whole thing is pretty much black magic at this point. I'm just glad it mostly works most of the time.

Link to comment
Share on other sites

Finally took some time this evening to understand a little bit more about C# and how the serial event stuff is working. Or, you know, isn't working.

Marzubus had the same problem with the Port.ReceivedEvent not being fired, and solved it in exactly the same way. No seriously, exactly the same way. Compare Zalta's use of MonoBehaviour.Update() here with Marzubus' implementation here.

Has anyone tried changing

while (Port.IsOpen && Port.BytesToRead > 0)

to

while (Port.IsOpen && Port.BytesToRead > 100)

or something?

There is no need to loop through the whole packet processing crap for every single byte, just do it couple of times when the USB serial buffer is filling up. The USB buffer is much larger so the risk of overflow is quite small.

Link to comment
Share on other sites

while (Port.IsOpen && Port.BytesToRead > 100)

I don't think it can go too large; it needs to be small enough for the handshake packets to be read, doesn't it?

This afternoon I played around with the plugin on Windows 10, leaving the BytesToRead threshold at 0, then increasing it to 3 to match what Port.ReceivedBytesThreshold is being set to, then going a little higher up to 10 and 15. All tests gave me the same result: the plugin would detect my arduino and log that to the screen. But then the game would hang before the scene was finished loading, leaving me at a black screen with UI elements loaded and the "opening serial port" message up. Worse still, it took a few hours of hair-pulling to realise that killing the game when it got in to that state left the serial port half-open and I had to reboot to run another test.

Link to comment
Share on other sites

It isn't actually that expensive to buy the simpler arduinos if you buy clones from China. I bought the pro mini clones I use in my modules for $3 each from Banggood.com and it should be possible to get close to $2 if you accept longer delivery times, buy a larger batch (i but I bought five at a time) or spend some time looking for a bargain on several web stores. The Pro Micro cost three times as much, need only one 32u4 to emulate all USB devices. The total cost for all arduinos was less than $40 and I still have one left over.

Trying desperatelly NOT to buy other 2 small televisions and 3 arduinos UNO to make an awesome simulator hardware.

Link to comment
Share on other sites

I don't think it can go too large; it needs to be small enough for the handshake packets to be read, doesn't it?

This afternoon I played around with the plugin on Windows 10, leaving the BytesToRead threshold at 0, then increasing it to 3 to match what Port.ReceivedBytesThreshold is being set to, then going a little higher up to 10 and 15. All tests gave me the same result: the plugin would detect my arduino and log that to the screen. But then the game would hang before the scene was finished loading, leaving me at a black screen with UI elements loaded and the "opening serial port" message up. Worse still, it took a few hours of hair-pulling to realise that killing the game when it got in to that state left the serial port half-open and I had to reboot to run another test.

.... forgot about the handshake. So does BytesToRead even work at all? If it does you can try increasing the size after the connection.

Link to comment
Share on other sites

  • 2 weeks later...

That looks like you've borked the timing to the 7 seg displays. What ever you added to the main loop is taking too much processing time.

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.

https://lh3.googleusercontent.com/-WIcqP646pNo/VOlSGYtwLUI/AAAAAAAABiI/vdCl_9a7qPg/s480/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.

- - - Updated - - -

Got the panels laser cut and painted today. Happy with how they came out, but I will need to cut the upper one again. Parts are interfering on the backside of the panel.

2rrt24z.jpg

Link to comment
Share on other sites

Question on SASTol setting: Right now I am flying with reduced hardware, only joysticks, throttle and stage button. It seems that once I pass SASTol limit, SAS is off until I reengage it via keyboard. Is that intended behavior?

It should reengage when you centre the stick? Basically if you are moving the stick manually it overrides SAS, but if you let go SAS take control.

BTW I've been doing a bit more research on the serial received event issue, doesn't look like there are any easy solutions. Let's see what happens with Unity 5.

- - - Updated - - -

Got the panels laser cut and painted today. Happy with how they came out, but I will need to cut the upper one again. Parts are interfering on the backside of the panel.

I wonder what the laser cutter place thought what the heck you were making :D

Link to comment
Share on other sites

It should reengage when you centre the stick? Basically if you are moving the stick manually it overrides SAS, but if you let go SAS take control.

It still lights up on the screen, but it does not actually work until I disengage and engage by keyboard. I have put the tolerance up to 0.25, will fiddle around.

Link to comment
Share on other sites

It still lights up on the screen, but it does not actually work until I disengage and engage by keyboard. I have put the tolerance up to 0.25, will fiddle around.

Did that help? :)

I added some code to quickly disengage and re-engage SAS if the joystick returned to all zeroes, and incrased the plugin refresh rate. Seems to only be the rotational axis, RCS lateral motion keeps the SAS active :)

Edited by AmeliaEatyaheart
Link to comment
Share on other sites

Did that help? :)

I added some code to quickly disengage and re-engage SAS if the joystick returned to all zeroes, and incrased the plugin refresh rate. Seems to only be the rotational axis, RCS lateral motion keeps the SAS active :)

Hmm.. I haven't touched the axis controls for a long time, maybe they changed something in 1.0? In the plugin only Roll, Pitch, Yaw has SAS manual override enabled.

The code is fairly simple:

if (Math.Abs(KSPSerialPort.VControls.Pitch) > SettingsNStuff.SASTol ||
Math.Abs(KSPSerialPort.VControls.Roll) > SettingsNStuff.SASTol ||
Math.Abs(KSPSerialPort.VControls.Yaw) > SettingsNStuff.SASTol)
{
ActiveVessel.Autopilot.SAS.ManualOverride(true);
}
else
{
ActiveVessel.Autopilot.SAS.ManualOverride(false);
}

I'll have a look at this.

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