Last active
October 27, 2020 07:44
-
-
Save danricho/55e193ba7de88f527500107577c04c85 to your computer and use it in GitHub Desktop.
MSFS2020 Arduino based control box with Python SimConnect interface
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
from SimConnect import * | |
import serial | |
import struct | |
def logit(strIn): | |
print(" " + datetime.now().strftime('%H:%M:%S.%f')[:-3] + " : " + str(strIn)) | |
def readLine(): | |
return arduino.readline().decode(encoding='UTF-8',errors='strict').strip() | |
def sendStatus(param,value): | |
arduino.write(param.encode()) | |
if readLine() == param: | |
arduino.write((str(value) + ";").encode()) | |
return readLine() | |
logit("Start") | |
arduino = serial.Serial('COM10', 9600) | |
logit("Serial Connected") | |
# N -> NAV1 RADIO | |
logit("NAV 1: " + sendStatus("N",111.005)) | |
# O -> NAV2 RADIO | |
logit("NAV 2: " + sendStatus("O",112.150)) | |
# R -> COM1 RADIO | |
logit("COM 1: " + sendStatus("R",123.45)) | |
# S -> COM1 RADIO | |
logit("COM 2: " + sendStatus("S",121.328)) | |
arduino.write("C".encode()) | |
logit(readLine()) # Read the newest output from the Arduino |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ignore - Gist Naming File |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TXO -> USB (PC) | |
RXI <- USB (PC) | |
GND | |
GND | |
D2 SDA -- I2C (LCD) | |
D3 SCL -- I2C (LCD) | |
D4 | |
D5 | |
D6 | |
D7 | |
D8 | |
D9 | |
D10 | |
D16 | |
D14 | |
D15 | |
D18 | |
D19 | |
D20 | |
D21 | |
VCC | |
RESET | |
GND | |
RAW 5V |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void setup() { | |
Serial.begin(9600); // set the baud rate | |
Serial.println("Ready"); // print "Ready" once | |
} | |
void loop() { | |
char inByte = ' '; | |
if(Serial.available()){ | |
// only send data back if data has been sent | |
char inByte = Serial.read(); // read the incoming data | |
float inFloat; | |
switch (inByte) { | |
case 78: // this is a NAV1 | |
case 79: // this is a NAV2 | |
case 82: // this is a COM1 | |
case 83: // this is a COM2 | |
Serial.println(inByte); | |
inFloat = Serial.parseFloat(SKIP_NONE); | |
Serial.read(); // trailing semi-colon | |
Serial.print(inFloat, 3); | |
Serial.println(""); | |
break; | |
default: | |
Serial.print("No Good, I received ASCII DEC: "); | |
Serial.println(inByte, DEC); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment