zitronen

[Hardware, Plugin] Arduino based physical display + serial port io+ tutorial (10-06-17)

Recommended Posts

Uh... does it change if you change the refresh rate in the plug config file?

Share this post


Link to post
Share on other sites

Guys, what is the actual output of ControlStatus();

I'm trying to turn on LEDs using a TLC5940 chip, using:

Tlc.set(PIN, map(ControlStatus(LIGHTS),LOW, HIGH, 0, 2000));

to no avail. Also tried mapping from 0, 1. (note, the Tlc5940 uses a range from 0, 4096 for output values.)=

The example provided in the code is digitalWrite(SASLED,ControlStatus(AGSAS));

any idea how I can get this to map to my (0,4096) range?

 

A.J.

 

Edited by ajden

Share this post


Link to post
Share on other sites

Hey-O. Figured it out. It's actually:

Tlc.set(0, map(ControlStatus(AGLight),LOW, HIGH, 0, 2000));

These 5940 chips work pretty well if you want to control a bazillion LEDs from your Uno. 

A.J.

Share this post


Link to post
Share on other sites

Hi, Im playing around with controlling SAS modes, and I can't get them to work,
Just wanting to clarify that 

void controls(){
  if (connected){
       if (ButtonState){
           setSASMode(2);
       }
       KSPBoardSendData(details(CPacket));
  }
}

should engage prograde SAS? if not what am I doing wrong

Edit: 

KSP version and Pluggin are up to date, Windows 10
Im using a mega 

Edited by ohMorrissey

Share this post


Link to post
Share on other sites

You need to do it like the example code:

if (digitalRead(SASPIN)) { //--------- This is how you do main controls
      MainControls(SAS, HIGH);
      setSASMode(SMPrograde); //setting SAS mode
      //setNavballMode(NAVBallSURFACE); //setting navball mode
    }
    else {
      //setNavballMode(NAVBallTARGET);
      MainControls(SAS, LOW);
    }

MainControls(SAS, HIGH/LOW) does the actual turning on and off.

Since you are using win10, check using the example code to see if you are getting any control inputs at all.

Share this post


Link to post
Share on other sites
On 1/11/2018 at 1:08 PM, zitronen said:

You need to do it like the example code:


if (digitalRead(SASPIN)) { //--------- This is how you do main controls
      MainControls(SAS, HIGH);
      setSASMode(SMPrograde); //setting SAS mode
      //setNavballMode(NAVBallSURFACE); //setting navball mode
    }
    else {
      //setNavballMode(NAVBallTARGET);
      MainControls(SAS, LOW);
    }

MainControls(SAS, HIGH/LOW) does the actual turning on and off.

Since you are using win10, check using the example code to see if you are getting any control inputs at all.

I am trying to do the same thing, i think.

I have a master switch for SAS ON/OFF. But I want 10 buttons to change the state of SAS once it is on. I have tried putting just a separate if statement but that doesn't seem to help

Share this post


Link to post
Share on other sites
30 minutes ago, JoshTheCoward said:

I am trying to do the same thing, i think.

I have a master switch for SAS ON/OFF. But I want 10 buttons to change the state of SAS once it is on. I have tried putting just a separate if statement but that doesn't seem to help

Well don't you just want to set different SASModes then?  

Read the various control states in front of you, build the table of what you should do then code it.  I.e., if main sas switch is set, and then there's a multi-select dial set to a specific mode, read the mode switches, then choose what to do.  If you have different buttons for different modes, you'll have to read the master SAS state, and select it, perhaps toggling a hidden state variable in your MEGA about whether the next button push enables, or disables the master SAS mode.  You might use encoding of a bit-field and read the field from another "sub-controller" on your board.  And switching SAS modes with SAS disabled may make sense (like if you have a rotary switch control), or it may not make sense (if you just have buttons that may, or may not light up if the mode is chosen, and the mode is active).  I.e. push prograde twice (once to switch from target to prograde, then from prograde to off).  

As in any control system, it really does help to make a little table of what things should be first, otherwise debugging becomes a pain in the neck.  I use whiteboards (easy to erase) or pencil (easy to refer to my sheet of paper).  Without knowing exactly what you're up to I think you're just looking to set various nav ball modes based on the user's switches, but since we don't know exactly what switches you have, it's hard to guess at what's best for you.

  

Share this post


Link to post
Share on other sites
1 hour ago, morgeturd said:

Well don't you just want to set different SASModes then?  

Read the various control states in front of you, build the table of what you should do then code it.  I.e., if main sas switch is set, and then there's a multi-select dial set to a specific mode, read the mode switches, then choose what to do.  If you have different buttons for different modes, you'll have to read the master SAS state, and select it, perhaps toggling a hidden state variable in your MEGA about whether the next button push enables, or disables the master SAS mode.  You might use encoding of a bit-field and read the field from another "sub-controller" on your board.  And switching SAS modes with SAS disabled may make sense (like if you have a rotary switch control), or it may not make sense (if you just have buttons that may, or may not light up if the mode is chosen, and the mode is active).  I.e. push prograde twice (once to switch from target to prograde, then from prograde to off).  

As in any control system, it really does help to make a little table of what things should be first, otherwise debugging becomes a pain in the neck.  I use whiteboards (easy to erase) or pencil (easy to refer to my sheet of paper).  Without knowing exactly what you're up to I think you're just looking to set various nav ball modes based on the user's switches, but since we don't know exactly what switches you have, it's hard to guess at what's best for you.

  

How do I get it to change state with button push? 

if (digitalRead(SMSAS)) {
       setSASMode(SMSAS);
  }

This doesn't seem to work

 

I want it to work: 

 

If SAS switch is on then:

         if prograde button is pushed then switch to prograde ....

else 

 SAS is off

 

 

Here is my code:

void controls() {
  if (Connected) {

    if (digitalRead(SASPIN)) { 
      MainControls(SAS, HIGH);

     if (digitalRead(SMSAS)) {
       setSASMode(SMSAS);
     }
  
    if (digitalRead(SMPrograde)) {
      setSASMode(SMPrograde);
   
    }
   
   if (digitalRead(SMRetroGrade)) {
     setSASMode(SMRetroGrade);
    } 
   
    if (digitalRead(SMNormal)) {
       setSASMode(SMNormal);
    } 

    if (digitalRead(SMAntinormal)) {
       setSASMode(SMAntinormal);
    } 

     if (digitalRead(SMRadialIn)) {
       setSASMode(SMRadialIn);
    } 
    if (digitalRead(SMRadialOut)) {
       setSASMode(SMRadialOut);
    } 
     if (digitalRead(SMTarget)) {
       setSASMode(SMTarget);
    } 
    if (digitalRead(SMAntiTarget)) {
       setSASMode(SMAntiTarget);
    } 

     if (digitalRead(SMManeuverNode)) {
       setSASMode(SMManeuverNode);
    } 
        
 
    }
    else {
      
      MainControls(SAS, LOW);
    }
    


 

Edited by JoshTheCoward

Share this post


Link to post
Share on other sites
16 hours ago, JoshTheCoward said:

I am trying to do the same thing, i think.

I have a master switch for SAS ON/OFF. But I want 10 buttons to change the state of SAS once it is on. I have tried putting just a separate if statement but that doesn't seem to help

I got the modes working when I coded it so that the SAS is always on when the code is running, and the button changed direction (Pro/Retro) when (HIGH/LOW) and worked, 

the example code only activated SAS when the button was (HIGH), might be a Win10 bug? still working towards doing exactly what you are trying to do but i'm gonna construct my panels first.

PS: The example worked but mine didn't, found it only worked when I copied all my added code back into a fresh set of demo16 files. Couldn't find any difference between my old code and the copy back into the fresh files but it worked after none the less.

Share this post


Link to post
Share on other sites

JoshTheCoward,

Have you named your inputs the same as the SAS modes? I'm not sure you can get that to work since higher up in the code the SAS modes are defined. Example: "#define SMPrograde   2"  is up in the header of the main tab in the code. 

So maybe if your Prograde button is hooked up to pin #2, the following would work

   if (digitalRead(SMPrograde)) {
      setSASMode(SMPrograde);

But this isn't ideal, since you start running into serial I/O pins that should ideally be left blank (depending on your platform). 

 

Other "gotchas":

Make sure you declare the pinMode(WhateverPin, INPUT_PULLUP); somewhere

After some tribulations I discovered that my pushbuttons were NC instead of NO. That made the coding a bit more of a pain.

I'm fairly new to this, so if any of the above is way out in left field, please correct me for posterity's sake.

  • Like 1

Share this post


Link to post
Share on other sites
On 1/13/2018 at 9:05 AM, ajden said:

JoshTheCoward,

Have you named your inputs the same as the SAS modes? I'm not sure you can get that to work since higher up in the code the SAS modes are defined. Example: "#define SMPrograde   2"  is up in the header of the main tab in the code. 

So maybe if your Prograde button is hooked up to pin #2, the following would work


   if (digitalRead(SMPrograde)) {
      setSASMode(SMPrograde);

But this isn't ideal, since you start running into serial I/O pins that should ideally be left blank (depending on your platform). 

 

Other "gotchas":

Make sure you declare the pinMode(WhateverPin, INPUT_PULLUP); somewhere

After some tribulations I discovered that my pushbuttons were NC instead of NO. That made the coding a bit more of a pain.

I'm fairly new to this, so if any of the above is way out in left field, please correct me for posterity's sake.

 

Ok so I rewrote it to 

 

That does not seem to work either. 

 

 

Update: I just re-assigned one of the buttons to my stage button and it worked no problem, do the physical button is working.

 

Update2: Never Mind I was using Serial inputs and it was messing it up.

Edited by JoshTheCoward

Share this post


Link to post
Share on other sites

@JoshTheCoward: That looks pretty cool. How did you make the print on the controller, and the markings inside the annunciators?

Just cheep decal paper from Amazon and then latex clear coat on top.

@Freshmeat 2 questions have you been able to program a map button using the Mode variable? How would that look?

 

I tried

 

  if (digitalRead(MAPPIN)) {
       CPacket.Mode = 2;
    } 

but that didn't seem to work. Also have you ever programed Max7219's? Having a real tough time with them, but that is probably because I have zero programing knowledge.

Edited by JoshTheCoward

Share this post


Link to post
Share on other sites

@JoshTheCoward The map mode is not implemented. My controller has a USB keyboard IC included to get keystrokes for map, IVA, next/prev ship, time warp and cycle view. As for MAX7219, I followed the tutorial on Arduinos website. Feel free to ask specific questions, and share your code and what you are trying to do.

The LEDs draw a lot of power, though, so be prepared to supply some extra juice to your controller. If you can get a 5V 2A wall wart for a tablet, it goes a long way. Otherwise an old PSU is assured overkill for everything you ever are going to hook up.

Share this post


Link to post
Share on other sites
On 1/28/2018 at 3:17 AM, JoshTheCoward said:

Just cheep decal paper from Amazon and then latex clear coat on top.

@Freshmeat 2 questions have you been able to program a map button using the Mode variable? How would that look?

 

I tried

 

  if (digitalRead(MAPPIN)) {
       CPacket.Mode = 2;
    } 

but that didn't seem to work. Also have you ever programed Max7219's? Having a real tough time with them, but that is probably because I have zero programing knowledge.

Unfortunately never figured out a way to switch to map view in the plugin.

Share this post


Link to post
Share on other sites

Any reason why my throttle would not want to go lower than about 30%? (At least not permanently, it "jumps" back) I don't have it enabled nor anything connected to the pin allocated to it.

Share this post


Link to post
Share on other sites
2 hours ago, Evolution said:

Any reason why my throttle would not want to go lower than about 30%? (At least not permanently, it "jumps" back) I don't have it enabled nor anything connected to the pin allocated to it.

Try to connect the pin to ground. If you leave a pin disconnected from everything, will have a low voltage (~150/200mV) spontaneously. 

Share this post


Link to post
Share on other sites

Any chance of seeing more data sent out by the mod? 

- Vehicle mass, engine thrust / Isp

- Pro/Retrograde, Normal/AntiNormal, Radial in/out, target/anti-target, manouver node vector

- time to ascending/descending node.

Edited by tf58

Share this post


Link to post
Share on other sites
On 2/2/2018 at 7:01 AM, zitronen said:

You can also disable the throttle input in the .cfg file.

Seems the issue was that I missed the bit of the OP that explained the different values, I had expected throttle to not be enabled at all by default but that was not the case so even with nothing connected I was getting weird behavior from the floating pins as ljkjl mentioned.

Share this post


Link to post
Share on other sites

OK - I'm done lurking on this thread... I've pulled the trigger on some ebay items and broken out my trusty Uno to start planning a cockpit controller.

Just wondering if someone could help straighten some thoughts I'm having while planning a build. I think I'm trying to solve problems that don't exist yet. You know.. the Kerbal way to troubleshooting, sort of like City Lights before Cities.

I've recently gotten on the road to doing a controller/cockpit for KSP and I'm OK with coding up Arduino scripts and interfacing hardware to the point that they work. But I also know that I lack a lot in the design knowledge to properly layout the cockpit.  I'm trying to wrap my head around how to balance out the design of the KSP controller with what I want to be available.

As I understanding it with this KSPSerialIO mod, the Arduino would be doing two primary jobs:

  • updating any output such as LED / indicators / digital displays
  • triggering events in KSP based on input from specific buttons, joysticks angles, switch states

At any point is the Arduino acting as a Keyboard emulator and sending a Key commands that would be read by KSP? I ask as I'm wondering if I should split the processing across two different Arduinos? i.e One that acts as a keyboard/joystick that talks to KSP via the standard Joystick USB connection, the other dedicated to just updating the indicators / displays that is sent from KSPSerial IO.

I'm not sure how much processing will be needed to handle the KSPSerialIO stuff. Only just starting the design, but so far I'm up to 45 x 7-segment digits, 8 analog dials, 50 toggle switches / buttons, 13 rotary dials, 40 status indicators. I'm planning on using some I2MCP23017 IO extenders for the arduino for the shear number of buttons and levers. I've also specced out that I'll need about 6 MAX7219 for the 7segment displays. With all this, I'm sort of going for a 1960's ASET MK1 landing can-alike. :) 

I've also setup a shell mod for executing actions that are currently not actionable in the standard setting menu. As an example, I've got a parking break action assigned to Alt-N (why? it was next to 'B' alright. it made sense to me at the time! :D), and have a button that sends that command to the PC to activate the parking break in KSP. So I expect that I should be able to have a "Deploy / Retract Solar panels" button that would send an obscure custom Keyboard command (ALT-* maybe?) and my mod will do similar code to All'Yall / ALCOR and just open all solar panels on the vessel without an action group needing to be assigned at all. The downside is I won't know the exact status of the panels unless I add extra packets to KSPSerialIO, or use an ActionGroup. Reasons for not using an AG is because I want to avoid AG's for stuff that I can pickup automatically in the code, (eg Solar, Radiators, antennas, scanners, etc) so I can leave most of them for stuff on a mission.

Is there any benefit to letting the PC handle the joysticks and as many buttons as I can shove onto it so it doesn't have to be processed by the Arduino? I've got a UnoR3 and while I know it's not the fastest out there, I still wanted to try to push as much game data to it as I can to keep displays and indicators updated. Or would my main bottleneck be the time it takes for the Arduino to process each incoming packet and control input doesn't really factor?

Share this post


Link to post
Share on other sites

From my own adventures, I think you will run out of RAM handling all that stuff, and I think that the processor speed will be a problem as well. Try getting a Teensy or Due, compared to the rest of the budget the investment will be minor. Those around here who actually knows stuff seems to be of the opinion that I/O extenders are quite slow, and you seem to be wanting a lot.

Share this post


Link to post
Share on other sites
3 hours ago, Freshmeat said:

From my own adventures, I think you will run out of RAM handling all that stuff, and I think that the processor speed will be a problem as well. Try getting a Teensy or Due, compared to the rest of the budget the investment will be minor. Those around here who actually knows stuff seems to be of the opinion that I/O extenders are quite slow, and you seem to be wanting a lot.

Thanks for the heads up. I'll keep an eye on ram as I go. Ill also research the thread again to see if anyone mentioned extenders, I might of missed it the first time around. 

From what Ive read, they are supposed to be able to run I2c > 1 MHz, even though the Arduino can't. But, I've yet to have any experience with those chips yet so if anyone has practical knowledge about them being slow, I'd love to know more.

Share this post


Link to post
Share on other sites

While the extenders are fast, the libraries are AFAIK not. I run a couple of LCD displays on I2C, and takes some pain to keep the communication to a minimum.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now