Jump to content

Rapidwolf

Members
  • Posts

    7
  • Joined

  • Last visited

Everything posted by Rapidwolf

  1. Thats awesome! I have a question for you though: Where did you get those white buttons? I wanted those for my project, but I couldn't find them cheap enough! I ended up having to go with toggle switches, but I made it so I can upgrade to those later.
  2. 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. 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!
  3. 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.
  4. 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. Guess I'll keep working on designs.
  5. That fixed it. *facepalm* I knew when I asked here that it would be something obvious! Thank you! It was left over, like you said. It was late when I was at that stage and I over looked it. I'm new to this LCD and serial stuff. What do you mean use a different COM? It sounds important. Does it matter that this is a character based LCD? That being said, my LCD is updating now, but it cuts out at random times. All the controls will cut out and the LCD will quit updating. It'll start up randomly, sometimes it won't come up at all. Is this related to that? Thanks again for your help guys!
  6. I'd like to start by thanking you for making this mod, Zitronen. I've been working with it off and on the last week and I'm having a ton of fun (and learning lots!). I'm finally going to be able to build the Kerbal Kontrol Panel I've been wanting! So things were going well. I've had the brakes, gear, lights, RCS, SAS, Abort, Stage, and throttle all working great on my breadboard circuit. Last night I tried adding an LCD screen with a serial backpack and things went south. When I have any code in for the LCD I can't use anything else. While in KSP I can see it finds the right port and all, but it says "No display found." Also, the lights stay off and none of the buttons work. I have the throttle set so it only comes from the controller, but when the LCD is programmed in, I can fully control from the keyboard. The controller doesn't even try. Also, the LCD screen says "0.00" but I'm guessing thats just from the "Setup" function? I've dabbled in programming for a long time, but I took a few years off due to school. I've also never messed with this sort of thing, especially the hardware end. Dealing with serial is totally new to me, so this is probably a dummy error. Specs: I have an Arduino Uno (The mega is on its way! ) The LCD is a 20x4 on pin 2 (I'll post the code too) I have THIS serial backpack on the LCD NOTE: I'm running out of pins and wire for my breadboard, so I don't have the LEDs functioning anymore. I've only altered the Output and the KSPIODemo12 tab for the LCD, so I'll include those two. MY CODE: #include <SoftwareSerial.h> SoftwareSerial lcd(3, 2); //LCD on pin 2 int k = 0; //Variable for the LCD update cycle //pins for LEDs #define GLED 5 //#define YLED 6 //#define RLED 7 //#define SASLED 11 //#define RCSLED 12 //#define CG1LED 13 //pins for input #define SASPIN 8 #define RCSPIN 9 //#define CG1PIN 10 #define THROTTLEPIN 0 #define STAGEPIN 7 #define ABORTPIN 10 #define LIGHTPIN 11 #define BRAKEPIN 12 #define GEARPIN 13 #define THROTTLEDB 4 //Throttle axis deadband //Input enums #define SAS 7 #define RCS 6 #define LIGHTS 5 #define GEAR 4 #define BRAKES 3 #define PRECISION 2 #define ABORT 1 #define STAGE 0 //Action group statuses #define AGSAS 0 #define AGRCS 1 #define AGLight 2 #define AGGear 3 #define AGBrakes 4 #define AGAbort 5 #define AGCustom01 6 #define AGCustom02 7 #define AGCustom03 8 #define AGCustom04 9 #define AGCustom05 10 #define AGCustom06 11 #define AGCustom07 12 #define AGCustom08 13 #define AGCustom09 14 #define AGCustom10 15 //macro #define details(name) (uint8_t*)&name,sizeof(name) //if no message received from KSP for more than 2s, go idle #define IDLETIMER 2000 #define CONTROLREFRESH 25 //warnings #define GWARN 9 //9G Warning #define GCAUTION 5 //5G Caution #define FUELCAUTION 10.0 //10% Fuel Caution #define FUELWARN 5.0 //5% Fuel warning unsigned long deadtime, deadtimeOld, controlTime, controlTimeOld; unsigned long now; boolean Connected = false; byte caution = 0, warning = 0, id; struct VesselData { byte id; //1 float AP; //2 float PE; //3 float SemiMajorAxis; //4 float SemiMinorAxis; //5 float VVI; //6 float e; //7 float inc; //8 float G; //9 long TAp; //10 long TPe; //11 float TrueAnomaly; //12 float Density; //13 long period; //14 float RAlt; //15 float Alt; //16 float Vsurf; //17 float Lat; //18 float Lon; //19 float LiquidFuelTot; //20 float LiquidFuel; //21 float OxidizerTot; //22 float Oxidizer; //23 float EChargeTot; //24 float ECharge; //25 float MonoPropTot; //26 float MonoProp; //27 float IntakeAirTot; //28 float IntakeAir; //29 float SolidFuelTot; //30 float SolidFuel; //31 float XenonGasTot; //32 float XenonGas; //33 float LiquidFuelTotS; //34 float LiquidFuelS; //35 float OxidizerTotS; //36 float OxidizerS; //37 uint32_t MissionTime; //38 float deltaTime; //39 float VOrbit; //40 uint32_t MNTime; //41 float MNDeltaV; //42 float Pitch; //43 float Roll; //44 float Heading; //45 uint16_t ActionGroups; //46 status bit order:SAS, RCS, Light, Gear, Brakes, Abort, Custom01 - 10 byte SOINumber; //47 SOI Number (decimal format: sun-planet-moon e.g. 130 = kerbin, 131 = mun) byte MaxOverHeat; //48 Max part overheat (% percent) float MachNumber; //49 float IAS; //50 Indicated Air Speed }; struct HandShakePacket { byte id; byte M1; byte M2; byte M3; }; struct ControlPacket { byte id; byte MainControls; //SAS RCS Lights Gear Brakes Precision Abort Stage byte Mode; //0 = stage, 1 = docking, 2 = map unsigned int ControlGroup; //control groups 1-10 in 2 bytes byte AdditionalControlByte1; //other stuff byte AdditionalControlByte2; int Pitch; //-1000 -> 1000 int Roll; //-1000 -> 1000 int Yaw; //-1000 -> 1000 int TX; //-1000 -> 1000 int TY; //-1000 -> 1000 int TZ; //-1000 -> 1000 int WheelSteer; //-1000 -> 1000 int Throttle; // 0 -> 1000 int WheelThrottle; // 0 -> 1000 }; HandShakePacket HPacket; VesselData VData; ControlPacket CPacket; void setup() { Serial.begin(38400); //LCD SETUP Serial.begin(9600); //Starts the serial for the LCD lcd.begin(9600); //Starts LCD lcd.write(254); //Calls special command lcd.write(0x10); //Sets BAUD to 38400 delay(500); //Waits 500 lcd.write(254); //Calls special command lcd.write(1); //Clears the LCD lcd.print(VData.G); //Displays the Gee forces (Only to start - output tab contains update function) initLEDS(); InitTxPackets(); controlsInit(); LEDSAllOff(); } void loop() { input(); output(); } void output() { now = millis(); controlTime = now - controlTimeOld; if (controlTime > CONTROLREFRESH){ controlTimeOld = now; controls(); } } void controls() { if (Connected) { if (digitalRead(SASPIN)) //--------- This is how you do main controls MainControls(SAS, HIGH); else MainControls(SAS, LOW); if (digitalRead(RCSPIN)) MainControls(RCS, HIGH); else MainControls(RCS, LOW); if (digitalRead(STAGEPIN)) MainControls(STAGE, HIGH); else MainControls(STAGE, LOW); if (digitalRead(ABORTPIN)) MainControls(ABORT, HIGH); else MainControls(ABORT, LOW); if (digitalRead(LIGHTPIN)) MainControls(LIGHTS, HIGH); else MainControls(LIGHTS, LOW); if (digitalRead(BRAKEPIN)) MainControls(BRAKES, HIGH); else MainControls(BRAKES, LOW); if (digitalRead(GEARPIN)) MainControls(GEAR, HIGH); else MainControls(GEAR, LOW); // if (digitalRead(CG1PIN)) //--------- This is how you do control groups // ControlGroups(1, HIGH); // else // ControlGroups(1, LOW); //This is an example of reading analog inputs to an axis, with deadband and limits CPacket.Throttle = constrain(map(analogRead(THROTTLEPIN),THROTTLEDB,1024-THROTTLEDB,0,1000),0, 1000); // This is so the LCD only gets every third packet (fixes refresh problem) if (k == 3){ UPLCD(); k=0; } else { k++; } KSPBoardSendData(details(CPacket)); } } void UPLCD() { lcd.write(254); //Calls the special command lcd.write(1); //Clears the screen lcd.print(VData.G); //Displays the Gee forces on screen } void controlsInit() { pinMode(SASPIN, INPUT_PULLUP); pinMode(RCSPIN, INPUT_PULLUP); // pinMode(CG1PIN, INPUT_PULLUP); pinMode(STAGEPIN, INPUT_PULLUP); pinMode(ABORTPIN, INPUT_PULLUP); pinMode(LIGHTPIN, INPUT_PULLUP); pinMode(BRAKEPIN, INPUT_PULLUP); pinMode(GEARPIN, INPUT_PULLUP); } void MainControls(byte n, boolean s) { if (s) CPacket.MainControls |= (1 << n); // forces nth bit of x to be 1. all other bits left alone. else CPacket.MainControls &= ~(1 << n); // forces nth bit of x to be 0. all other bits left alone. } void ControlGroups(byte n, boolean s) { if (s) CPacket.ControlGroup |= (1 << n); // forces nth bit of x to be 1. all other bits left alone. else CPacket.ControlGroup &= ~(1 << n); // forces nth bit of x to be 0. all other bits left alone. } The code probably looks messy, I'm going to clean it up once I get everything working and the Mega hooked up. Any ideas on what I'm doing wrong? I can send the logs too if you'd like, but they just say "Found on COM3" and then "No display". Thanks in advance for your help! And thanks for this awesome mod!
×
×
  • Create New...