Created
August 18, 2015 23:58
-
-
Save robertcedwards/2f7a061af8ccc987aab2 to your computer and use it in GitHub Desktop.
Assetto Corsa Fan Control using Python API & Arduino
This file contains 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
import os | |
import sys | |
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "dll")) | |
import ac | |
import acsys | |
import serial | |
import time | |
#ser = serial.Serial(3, 9600) | |
ser = serial.Serial(port = 'COM4', baudrate = 9600, timeout = 0) | |
count = 0 | |
def acMain(acVersion): | |
# do something with serial library | |
global ser | |
ac.log("called acMain()") | |
time.sleep(3) | |
#ser.write("1:0;".encode()) | |
ser.write("3:17000;".encode()) | |
return "Arduino Serial" | |
def acUpdate(deltaT): | |
global ser,ac,acsys,count | |
if count == 15: | |
value=ac.getCarState(0,acsys.CS.SpeedMPH) | |
value = str(round(value)) | |
toSend="1:" + value + ";" | |
ser.write(toSend.encode()) | |
gear=ac.getCarState(0,acsys.CS.Gear) | |
gear = int(gear) | |
gear = gear - 1 | |
if gear == 0: | |
gear = "n" | |
elif gear == -1: | |
gear = "r" | |
else: | |
gear = str(gear) | |
toSendGear = "2:" + gear + ";" | |
ser.write(toSendGear.encode()) | |
count = 0 | |
else: | |
count = count + 1 | |
def acShutdown(): | |
global ser | |
ac.log("called acShutdown()") | |
ser.close() |
This file contains 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
#include <AccelStepper.h> | |
AccelStepper stepper(1, 2, 3); | |
const String keyRev = "1"; | |
int speed; | |
int previous; | |
String vRev = "0"; | |
int delimiter = 59; // means: ; | |
char data[80]; | |
void setup() { | |
Serial.begin(9600); | |
pinMode(13, OUTPUT); | |
pinMode(11, OUTPUT); | |
stepper.setMaxSpeed(1000); | |
stepper.setSpeed(100); | |
stepper.setAcceleration(500); | |
} | |
void loop() | |
{ | |
while (Serial.available() > 0) { | |
Serial.readBytesUntil(delimiter, data, 80); | |
String command = String(data); | |
if (command.substring(0,1) == keyRev) { | |
vRev = command.substring(2); | |
} | |
memset(data, '\0', 80); | |
} | |
if (vRev.toInt() > 5) { | |
speed = vRev.toInt() * 15; | |
stepper.moveTo(speed); | |
stepper.run(); | |
//previous = speed; | |
} | |
else { | |
digitalWrite(11, LOW); | |
} | |
} |
I think I need some help. I can not add the acsys library to python, it gives an error how can i not do it.
Hi, do you know where do i get the AC module? (pip command maybe?)
@demirkolerme & @andersonvnicius & @pippalTA It looks like you might need to enable Python in Assetto Corsa in
"Documents\Assetto Corsa\cfg\gameplay.ini"
Look for this line and change it to 1
[PYTHON]
ENABLE_PYTHON=1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@pipplalTA Hello! I believe it is using pySerial. Maybe you need to install that as a prerequisite? I'm getting this up and running again for my new sim setup so I'll be installing this again. So I'll let you know what I find...