Jump to content

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


zitronen

Recommended Posts

Sending delta data packets sounds like a fun thing to try, but it complicates the protocol significantly. I do like the thought of eliminating floating-point jitter in the plugin rather than relying on arduino code to do it.

A couple of other thoughts for increasing the refresh rate:

* Bump the serial speed to 250000. Because of the way the Arduino generates clock pulses for serial data, that speed has much lower jitter and error rate than others. It's a popular trick in 3D printer firmwares for this reason.

* Increase the serial RX buffer. Right now the arduino needs to do three or four Serial.read() calls to assemble a full KSPSerialIO data packet. I suspect that increasing the buffer to reduce the number of calls required will mean less load on the arduino. But I'm not sure yet. :)

Link to comment
Share on other sites

I did boost the serial buffer to 256. That has made a difference, at 115200 I haven't had any missed packets anymore. I had been seeing about 10/minute. I've got a variable watching the occurrences of "EF" and the number of times the function returns a true result. Counting the deltas, so far it is holding steady at Zero now.

Link to comment
Share on other sites

I did boost the serial buffer to 256. That has made a difference, at 115200 I haven't had any missed packets anymore. I had been seeing about 10/minute. I've got a variable watching the occurrences of "EF" and the number of times the function returns a true result. Counting the deltas, so far it is holding steady at Zero now.

Cool, I was thinking about experimenting with the buffer size. I believe some of the weird problems like random drop-offs people are having maybe caused by this, especially if their code is more complex and there's no time to read the whole packet before the next one arrives. If someone else can confirm this is helping I will put a note up on the first post.

Link to comment
Share on other sites

Just to leave a note, I did start a repository for "KSPIO Avionics" using your demo and the TVout Library for arduino (I'm using MEGA, but it should work with any atmel MCU that is compatible with the TVOUT library).

https://github.com/Scoppio/KSPIO-AVIONICS

I managed to pull an artificial horizon using some trigonometrics and drawing lines, very simple but made me super-happy when I saw it working :D

By the way, I will try to fork your project to add it to the toolbar or something like it so I can try to manually start/stop a connection and manualy chose the COM line to communicate with the output. Since I'm doing avionics, I need to verify if they respond on-the-fly, and it causes some headache to me when I need to close the connection with the arduino, recompile it and then go back to the vessel in KSP... It would really make my life easier if I could manually connect/disconect :)

Link to comment
Share on other sites

Very cool project. How does the mega keep up with the load from TVOUT? I've had problems with the millis() function being off, and some searching said it was a general problem. I have bookmarked your code and will steal from it with great enthusiasm.

EDIT: Read your post, and see that you have come to the same conclusion as I did: A slave is pretty much required for more advanced stuff.

Edited by Freshmeat
Link to comment
Share on other sites

Hi,

Thanks for developing this project.

I'm trying since this morning to make it working, a lot of tries .......

I'm having issue with "Display Not Found" and Windows 10, i try a lot of solutions like changing rate, refresh, some waiting variables, version 0.17.3 and 0.17.4(with Demo13), but nothing worked.

KSPSerialIO: trying default port COM3
KSPSerialIO: KSP Display not found
KSPSerialIO: trying port \Device\Serial0 - COM1
KSPSerialIO: KSP Display not found
KSPSerialIO: trying port \Device\USBSER000 - COM3
KSPSerialIO: KSP Display not found

I investigated with a Debug() method in the Arduino Code and a Serial Monitor.

-The plugin test the default COM (COM3 for my Arduino, another one, and again the Arduino but with a different name)

-The KSPBoardReceiveData() were true just one time : for the handshake

-The handshake sent by plugin is : BE EF 04 00 03 01 04 02

-The handshake sent by Arduino is : BE EF 04 00 01 02 03 04

-In your plugin code at github i see that M1/M2/M3 should be 03/01/04

I suspect the reason is that handshake response from Arduino to Plugin is not 03/01/04, because of this code :

if ((HPacket.M1 == 3) && (HPacket.M2 == 1) && (HPacket.M3 == 4))                            {
DisplayFound = true;
}
else
{
DisplayFound = false;
}

But i also saw that : :huh:

HPacket = new HandShakePacket();            
HPacket.id = HSPid;
HPacket.M1 = 1;
HPacket.M2 = 2;
HPacket.M3 = 3;

i'm totaly lost ...

I'm suspecting a handshake problem, but i don't know how to compile your source code to try some modifications (like place the debug handshake function HandShake()).

Link to comment
Share on other sites

Just to leave a note, I did start a repository for "KSPIO Avionics" using your demo and the TVout Library for arduino (I'm using MEGA, but it should work with any atmel MCU that is compatible with the TVOUT library).

https://github.com/Scoppio/KSPIO-AVIONICS

I managed to pull an artificial horizon using some trigonometrics and drawing lines, very simple but made me super-happy when I saw it working :D

By the way, I will try to fork your project to add it to the toolbar or something like it so I can try to manually start/stop a connection and manualy chose the COM line to communicate with the output. Since I'm doing avionics, I need to verify if they respond on-the-fly, and it causes some headache to me when I need to close the connection with the arduino, recompile it and then go back to the vessel in KSP... It would really make my life easier if I could manually connect/disconect :)

When you leave the flight scene, e.g. go back to VAB, space centre it disconnects and you can use the serial port to upload code. When you go back to launch it will reconnect again.

Link to comment
Share on other sites

Zitronen, thats what I do :)

@Freshmeat

Yeap, you cant do any kind of sincronous action using the TVOut library without some nasty problems. It is also causing problems receiving data from kspio. Etc... A slave MCU will fix the problems.

Link to comment
Share on other sites

For the Windows 10 problem, maybe this could help :

I compile myself your code (0.17.4) and the SerialPort.dll for .NET 4.5 and add some debugging lines.

I think the problem is from the event or the delegate (i don't remember how this work in C#)

The computer receive the handshake from the Arduino, i saw it with a Serial monitor.

But the Plugin never go in this method :

private void Port_ReceivedEvent(object sender, SerialReceivedEventArgs e)

I put a long wait in this loop to be shure :

while (Port.BytesToRead == 0 && k < 15 && !DisplayFound)

{

Thread.Sleep(1000);

k++;

}

Link to comment
Share on other sites

In case anyone needs it - I've updated the maxmatrix library to write to multiple chained 7seg displays. At the moment it assumes an 8 digit display and is probably not as efficient as it could be. This is for displays utilizing the MAX7219 driver.

Link to comment
Share on other sites

For the Windows 10 problem, maybe this could help :

I compile myself your code (0.17.4) and the SerialPort.dll for .NET 4.5 and add some debugging lines.

I think the problem is from the event or the delegate (i don't remember how this work in C#)

The computer receive the handshake from the Arduino, i saw it with a Serial monitor.

But the Plugin never go in this method :

I put a long wait in this loop to be shure :

Yes, there is some kind of weird problem with the receive event on Windows 10. I don't know what's going on. I don't have windows 10 right now to do tests, if anyone can help with debugging it would be great.

Link to comment
Share on other sites

I can help if you tell me what to do.

Except I don't know what to do!! I was hoping you would have some ideas :D I might get an old laptop and put win10 on it at some point.

You can read all the things we tried from post #1157 - #1177. My coding skills is not great, so it could easily be something wrong with the way the code is written.

Link to comment
Share on other sites

Hum, i can have some ideas like everyone, but i'm not skilled for that.

I already read and try everything from there ...

The problem is that the Port_ReceivedEvent no received event.

I'm pretty sure that the delegate ( Port.DataReceived += Port_ReceivedEvent;) works well, because i use a Debug to check.

So the problem could come from the SerialPort.dll, but i understand nothing in the SerialPort source code, too complex for me.

Maybe (maybe !!!) the SerialPort.dll is too old, but you should have a reason to use it.

i don't know why your are not using this Class : https://msdn.microsoft.com/en-us/library/system.io.ports.serialport(v=vs.110).aspx

So for the moment i try some experiments, i'm trying to use the System.IO class. But i'm not a programmer, so i'm just playing with luck.

Link to comment
Share on other sites

Ok so i made other tests :

I use the PsimaxSerial library made by Marzubus.

1/Use Marzubus version (0.17.0) : Nothing more happen

2/I use PsimaxSerial in your 0.17.4 code and modify SerialPort class a little to use PsimaxSerial : Nothing more.

I'm out of idea, if someone have a suggestion.

Link to comment
Share on other sites

The solution is to remove the event, and work with Update() or FixedUpdate().

Edit :

I found a working solution, it's working now :D:D:D

1/I replace the function call by the event by a simple function (just change name and parameters).

2/I create and Update() in the Class KSPSerialPort to call the function

3/ I use PsimaxSerial.dll, it works better than the OpenNETCF dll, because the Port.BytesToRead seems to be broken too.

I have to continue testing to check if everything is fine.

Edited by Zalta
Link to comment
Share on other sites

The solution is to remove the event, and work with Update() or FixedUpdate().

Edit :

I found a working solution, it's working now :D:D:D

1/I replace the function call by the event by a simple function (just change name and parameters).

2/I create and Update() in the Class KSPSerialPort to call the function

3/ I use PsimaxSerial.dll, it works better than the OpenNETCF dll, because the Port.BytesToRead seems to be broken too.

I have to continue testing to check if everything is fine.

Nice work. Is bytestoread always returning 0? That could explain what's going on. Forcing it to update all the time is not as efficient at the event based method, can you try PsimaxSerial.dll with the original code?

Link to comment
Share on other sites

Yes BytesToRead always return 0 with OpenNETCF.

I already check the original code with PsimaxSerial, that don't work, the reason it's not the event, it's the Arduino that do not receive well packets.

But packets sent with Psimax/Original code and Psimax/event removed are the same ...

My Arduino is so silly ...

I use 0.17.4 code (git master) and Demo13.

Link to comment
Share on other sites

Nice work! I finally found the time to get my gaming rig dual-booting Windows 7 and 10, but you seem to have fixed it before I had a chance to be confused by the serial code. :)

Any chance you care to share your code? I'd be happy to help test it on Windows 10, and I also have OS X and Linux boxes I'd be keen to give it a bash on. Would be nice to unify this and Marzubus' previous efforts.

Link to comment
Share on other sites

I will share it, first i have to understand how github works and how my new IDE works with Github. :blush:

Can you try this : http://www.filedropper.com/kspserialio

You will find :

KSPSerialIO.dll_work

KSPSerialIO.dll_dontwork

Just rename one of thoose in KSPSerialIO.dll and test.

Could you test both ? The working one is without event, the don't working one is the event. (Both use PsimaxSerial)

Use this demo : https://sites.google.com/site/zitronfiles/KSPIODemo13.zip

Just check the Baudrate in the config file and the Arduino program before use, it might be different.

Because like zitronen said, it's better to use event.

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