Jump to content

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


zitronen

Recommended Posts

Ok, I need some help if anyone is willing.  I am trying to set this up in preparation for building the controller [from Instructables], and I have been met with nothing...but failure. 

At this point, I'm just trying to get the first demo to work [using demo16 code.] I have tried with both Arduino Uno and Mega. And I have tried on both Windows 10 and Linux.  The code seems to upload fine. When I start the game I get a couple of board lights flash, then when I load a ship I get "IO Awake" "No display found".   And thats it. Nothing at all when the ship launches.  I've double checked the plugin config, and I have the right Com port. Any help would be great. 

Link to comment
Share on other sites

@wile1411 I think your plan of splitting the USB HID keyboard stuff and the serial stuff to 2 arduinos is a good one, it's what I use. I would suggest not to plan too far ahead, start with something simple, once you get it working try something more complicated.

2 hours ago, Vipermp said:

Ok, I need some help if anyone is willing.  I am trying to set this up in preparation for building the controller [from Instructables], and I have been met with nothing...but failure. 

At this point, I'm just trying to get the first demo to work [using demo16 code.] I have tried with both Arduino Uno and Mega. And I have tried on both Windows 10 and Linux.  The code seems to upload fine. When I start the game I get a couple of board lights flash, then when I load a ship I get "IO Awake" "No display found".   And thats it. Nothing at all when the ship launches.  I've double checked the plugin config, and I have the right Com port. Any help would be great. 

Do you have the debug log? The win 10 has issues, you might need a different usb-serial converter, I'm not sure what the current status of the Linux version is.

Link to comment
Share on other sites

5 hours ago, zitronen said:

@wile1411 I think your plan of splitting the USB HID keyboard stuff and the serial stuff to 2 arduinos is a good one, it's what I use. I would suggest not to plan too far ahead, start with something simple, once you get it working try something more complicated.

Thanx @zitronen. Thanks for the reply. Was hoping seperating functions for the gate wasn't being overly careful. 

Plan is to do a throttle control first that has buttons for full & cut throttle. That should keep me busy for a bit.

Link to comment
Share on other sites

19 hours ago, zitronen said:

@wile1411 I think your plan of splitting the USB HID keyboard stuff and the serial stuff to 2 arduinos is a good one, it's what I use. I would suggest not to plan too far ahead, start with something simple, once you get it working try something more complicated.

Do you have the debug log? The win 10 has issues, you might need a different usb-serial converter, I'm not sure what the current status of the Linux version is.

I can get it.  Where would I find it?  And do you happen to have a link to the converter?  I'm not opposed to going direct to that route. 

Link to comment
Share on other sites

Link to comment
Share on other sites

I'm going through the current packet contents and found there is a lot of savings to be had depending on what I plan to implement. For my displays, I've found there is a lot that doesn't need to be displayed at the same time for my goals.

Also, I've found that I can reduce a good number of 4 byte floats to a 1 byte value. 0-100% maps to 255 with good resolution and the gauge only gives the indication of amounts as a percent anyway. I've got my packet plan down to 132 bytes at the moment, but I'm rapidly filling it back up with various system statuses and flags.

Note: This isn't asking for any specific changes or anything. I just thought I'd share my thoughts for those that might be thinking that the data packet is already full and are OK with a little bit of coding.

Edited by wile1411
Link to comment
Share on other sites

On 11/02/2018 at 4:31 PM, Freshmeat said:

While the extenders are fast, the libraries are AFAIK not.

This is what it comes down to. The Arduino Wire library is synchronous, and has a 32 byte message limit.

My build receives a data packet from the game, and relays that to a few slave microcontrollers over I2C. I was only able to do that by writing my own I2C library based on the Atmel TWI application notes.

Edited by stibbons
Link to comment
Share on other sites

Weee! progress has begun and a big thank you to @zitronen for the demo code. Works very well to get things started.

I managed to get the LEDs and buttons from the demo bread-boarded and working no probs. I then immediately scrapped it all and tried to use a spare adafruit LED Matrix driver - HT16K33 to force it to be a 16 Digit, 7 segment display board. I know it's complete the the wrong thing to use for this purpose, I2c not SPI - so not fast (not noticing it a this point), no font library (just used a HEX lookup table), wired for a matrix , not a segment display (didn't stop me from working around it).

Stupid thing is ordered left to right 76543210, but the direct digit references are 3210|3210 to get around having two quad displays on the first 4 cathodes (of 8) But I didn't let it stop me and rewrote the library so it works for 8 digit display wired it so there was 2 cathodes per line and then added each of the 16 anodes from the 2 x quad LED displays. Total hack job, but I just wanted to trial getting some numeric data out of the KSPSerialIO mod, rather than just blinky lights.

edit: I'll give this another shot tonight to rewire it (and recode) so the digit position reference uses the full 0-8 cathode list for easier referencing in code. Thinking about it on the bus this morning, I realised it was horrible to have to count from 0-3 and then have an if statement subtract 4 for the digits in positions 4-7. That way I can just have a 16 bit line (0111111100000110) where first 8 bits for each character are for the  first line of 8 digits, and the remainder of 8 bits in the 16 bit array are for the second line of 8 digits.

Piccy of the hack below displaying my RCS levels. I've also changed it to show Radar Altitude so it gets to use all 8 digits for this first row. I'll probably pull the whole thing apart again when I finally get a few of the MAX7219 chips. But it's a good first jump into a KSP  / Arduino combination. :)  It's actually not as bright as the picture give the impression. I just haven't cleaned the lens on my phone. 

lB9GBDWh.jpg

On ‎16‎/‎02‎/‎2018 at 4:54 AM, stibbons said:

This is what it comes down to. The Arduino Wire library is synchronous, and has a 32 byte message limit.

My build receives a data packet from the game, and relays that to a few slave microcontrollers over I2C. I was only able to do that by writing my own I2C library based on the Atmel TWI application notes.

I'll probably do something similar. Plan is to have a few 7219s dealing with output, something else for the 2x16 LCD display and the above 16x8 matrix will probably end up what drives all the lights on the controller. I've got a new protocol planned that sets all the light / indicator bits into a few bitmasks on my PC where the grunt is . Next step is to just have the HT16K33 microcontroller update the matrix without too much logic required.

I'm sure I'll run into the speed issue down the track and will need to start looking for speed savings at some point. To help mitigate it, all input will be from a separate Arduino that will be running mmJoy2. From what I've read it'll probably be ideal for what I'm looking for. Just need to stock up on a bunch of diodes for all the buttons, toggle switches and dial selectors.

Edited by wile1411
Link to comment
Share on other sites

Following @stibbons lead, I tore out an old PSU from an abandoned PC. Has 12V, 5V and 3.3 V with a lot more amperage than I need, drawn from the motherboard molex connector. I thought about buying a wall wart as the efficiency rating of the PSU at low load is supposedly atrocious, but it was free and had the correct voltages. The 5V is connected to Vin on my Mega board, and both 5V and 3.3V are connected directly to the perfboard that hold all my circuitry. Ground is of course shared between the units. Downsides are the power consumption, as noted, and the physical size that made for some interesting layout callenges while building the actual controller.

 

Link to construction

Edited by Freshmeat
Link to images.
Link to comment
Share on other sites

5 hours ago, Freshmeat said:

Following @stibbons lead, I tore out an old PSU from an abandoned PC. Has 12V, 5V and 3.3 V with a lot more amperage than I need, drawn from the motherboard molex connector. I thought about buying a wall wart as the efficiency rating of the PSU at low load is supposedly atrocious, but it was free and had the correct voltages. The 5V is connected to Vin on my Mega board, and both 5V and 3.3V are connected directly to the perfboard that hold all my circuitry. Ground is of course shared between the units. Downsides are the power consumption, as noted, and the physical size that made for some interesting layout callenges while building the actual controller.

 

Link to construction

Thanks for the suggestion - that does sound a lot simpler than what I was thinking. Initial plan was to use an AC to DC 12v 5A power pack and have a buck connector for the 5v line for the microcontroller and other chips.

I'll read up on ATX supplies for Arduino projects. I vaguely  remember there are drawbacks or things I need to consider like about power stability / spikes. More research needed. Cheers.

Link to comment
Share on other sites

  • 3 weeks later...

"helluu" again:     KSP V1.4.1 / Serial IO V1.4 / Arduino V18.4 (?  i have the *.ino-base with just 54 attributes to TargetdV) / Win7

meanwhile it runs stable as desired in background. 

switches acting a like slow, but so far so good. 

 

 

 

                               

 

 

Edited by sec3
Link to comment
Share on other sites

On 2/13/2018 at 9:51 PM, Freshmeat said:

Gah! I've had this working no problem on Win10 for a bit using an Arduino Uno and an I2C breakout board to some segment displays.

Now that I've moved to a MAX7219 with the same segment displays using SPI, my KSPIODemo16 wont connect anymore and has 3 resets each time I tried to load a vessel. Is there any collective wisdom on possible causes for the Arduino to be reset?

At the moment my symptoms are:
 - Plugin and start up the arduino I'm seeing the " - - - " on the segment displays that I set when there is NO connection from KSP
 - I changed the sketch to have CONTROLREFRESH=250 so I can see what's going on.
 - When I have KSP open and switch to a vessel from the space center, I can see the indication i added to the sketch that the Uno reset for a brief moment (first segment lights up with 'a' value to show reset). This repeat 3 times and then the scene loads and there are no more reset/connection attempts.

Just wondering if I could get some pointers on where to troubleshoot this?

*sigh* TIFU :confused:
Lesson learnt: Don't accidentally remove the line that is blazingly obvious that it's rather vital to communicating to the PC:   

Serial.begin(38400);

TIL: Also check the small things first before even thinking of posting to the forum. :blush:

 

 

Link to comment
Share on other sites

So the fun begins......

I'd like to say a big thanks to everyone that has contributed to this project.  :)

Ill do my best to share any information that I learn in the process.

For anyone interested I have tested the KSPIODeom16 on windows 10 using both an arduino uno (brand name and elegoo) and the mega (elegoo and arduino brand) boards on windows 10 with no immediate issues.

I have started out with displaying altitudes on 3 different 7 segment displays running off MAX7219s.  It seems if the main loop goes to long the arduino will not connect to the computer.  To accomplish writing to 3 different displays I only write to one display per loop.

My current delema is writing levels to the adafruit ic2 24 segment bargraphs, it seems as if the adafruit LED library that is used is taking too long on each write and this is causing the arduino to not connect to the pc.
My thoughts on this (after skimming through this forum) is to use 2 arduinos.  For anyone out there who has done this is my best bet using ic2 or serial communication between the two?  Or perhaps is there a better way to transfer data.

I am thinking to send the parameters needed to drive all of the displays and indications to the slave arduino.  The slave can then take however much time it needs to crunch the numbers and write to the displays without slowing down the master arduino connected to the PC.   

again thanks to all.  Ill do my best to help others, I am new so don'hold your breath.

Link to comment
Share on other sites

Hi @TommyH , welcome aboard.

Do not feel intimidated by microprocessors, when I started building mine I knew Ohm's law and had an old soldering iron. Last time I had done any coding was roughly in the previous millennium.

As @stibbons can explain in great detail should he feel so inclined, getting multiple Arduinos to talk is a nightmare. The original I2C protocol is limited to 32 bytes per package, and quite slow as well. What you can do, however, is limiting the number of times that you write to the displays. I have parts of my display update every half second, as that is roughly as often as I need them. In your case, instead of refreshing one display every loop, you could refresh one every other loop. Also, your conversions from VData to something your 7segs can display might be cumbersome, and Stibbons (again) did write some really fast conversion functions in a library.

Whatever you choose, good luck on your ventures and keep us posted.

Link to comment
Share on other sites

8 hours ago, TommyH said:

My current delema is writing levels to the adafruit ic2 24 segment bargraphs, it seems as if the adafruit LED library that is used is taking too long on each write and this is causing the arduino to not connect to the pc.

@Freshmeat is right, the standard Arduino Wire library is great for simple projects, but very slow. It sends data synchronously, and that's almost certainly what's slowing your sketch down enough to lose sync.

It also has an internal 32 byte buffer, so if you try to start using it to send KSPSerialIO data packets, you'll find yourself having to loop through the packet half a dozen times to send it, and then the receiver will have to loop through half a dozen times to assemble the fragments again. All using the synchronous interface. It's probably going to fail. :/

Using I2C is a great way to send to slave controllers; in my setup I'm using an Arduino Mega to handle the serial connection to my PC, and whenever it gets a data packet from the game it immediately rebroadcasts it over I2C to three slaves. You just won't be able to use the Wire library to do it.

Have a look at my KerbalController sketch. The TWI_Master library there is a much lower-level I2C library, which makes full use of the I2C hardware built in to the Atmega chips on Arduino Uno and Mega boards. The code in twi.ino sends vesseldata packets from the game, as well as my own data packet, that's used internally in the controller for things like setting the display mode and brightness.

The KerbalDescent sketch is a fairly simple example of how my slave controllers work. They use a TWI_Slave library, the slave counterpart to the TWI_Master lib.

Hope that helps.

Link to comment
Share on other sites

7 hours ago, stibbons said:

@Freshmeat is right, the standard Arduino Wire library is great for simple projects, but very slow. It sends data synchronously, and that's almost certainly what's slowing your sketch down enough to lose sync.

stibbons & freshmeat

Thanks for the advice, I am going to look into your sketches.  I appreciate your work on this.  Getting the arduinos to chit chat and coming up with a design for a mini alarm tile should keep me busy for the next week.  It will also keep my wife and kids sick of this project :).

Thanks!

Link to comment
Share on other sites

Hello! Just ordered stuff to basically copy Hugo Peeters  panel as featured in Make Magazine. For fun I've also ordered a Lattice semiconductor FPGA eval board to delegate some of the switch I/O and control to make the Arduino code even easier.

Anyway, I'd really appreciate it if someone could bring me up to speed with the story on Windows 10. Does the latest version work bi-directionally? Do I need to mimic a keyboard? I apologize if this is a real newbie question .. I've searched around the forum and couldn't quite get the full picture on Win10 compatibility. Thanks!

Link to comment
Share on other sites

6 hours ago, KerbalBoy said:

Hello! Just ordered stuff to basically copy Hugo Peeters  panel as featured in Make Magazine. For fun I've also ordered a Lattice semiconductor FPGA eval board to delegate some of the switch I/O and control to make the Arduino code even easier.

Anyway, I'd really appreciate it if someone could bring me up to speed with the story on Windows 10. Does the latest version work bi-directionally? Do I need to mimic a keyboard? I apologize if this is a real newbie question .. I've searched around the forum and couldn't quite get the full picture on Win10 compatibility. Thanks!

Hi KerbalBoy, welcome aboard.

Unfortunately, compatibility with windows 10 is a matter of try and see. Many boards work just fine, others refuse no matter what you tell them. If you are unlucky, you can buy a €1 usb->twi serial port and connect to your Arduino through that instead.

Using a Arduino Uno or Mega wioll not give you keyboard emulation, you need a Leonardo or Due for that, but KSPSerialIO does not need to emulate a keyboard. It just sends commands to KSP itself.

Hope this helps, good luck on your endeavor and keeps us posted. Feel free to ask questions, this thread is a friendly place.

Link to comment
Share on other sites

Progress.....

The Arduino is unforgiving....  one small typo, or assigning 1 pin two times will suck up an entire evening. 

Anyhow, I have made some progress towards getting prototype #1 fully functional. I think the throttle assembly and the small 3X alarm tile assembly (used in movie for displaying what velocity is displayed) turned out great. I have to figure out a more efficient way to build the small alarm boxes. Glueing each one piece by piece takea forever.

the Chinese max7219 7 segment displays are also a little finicky. 

If you have more time than you know what to do with and want to watch a small demo take a look at the video. 

Again thanks to everyone!

KSP Custom Controller prototype #1

 

Link to comment
Share on other sites

Good going. Also saw part of your CNC router timelapse, I am not at all envious.

For alarm boxes, I do not recall by whom I got the idea, but I use a small 3d printed grid box beneath a piece of acrylic glass. Cardboard can work as well, but I have access to a small amount of 3d printing. A piece of paper between the box with appropriate labels, and suddenly it looks a lot like real annunciator boxes.

Link to comment
Share on other sites

That annunciator box is what drove my design.   I work at a nuke plant and we use a similar style annunciator tile system. A lot of what I have invisioned comes from the look of how our control room. It has changed little from the 70s.  I’m sure my end product will have little resemblance... but it’s one of my ideas.  

the CNC machine is a great tool to have. I thought I’d buy one toss some wood up on it then make anything.   The reality was a little different, but after about  1 1/2 years I have it dialed in And it has been working well.  the cad and cam do take a lot of time, but I enjoy it.

 For this project I wish I had access to a 3D printer, I would guess that they are better suited for this style work. 

Did you use one piece of acrylic for the entire annunciator box?  I was unsure if the light diffusion through the acrylic would make it look like multiple tiles were lit.  I set it up such that each box has its own little piece of acrylic.  that was the main reason for the lengthy construction. 

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