blackleg Posted August 8, 2012 Posted August 8, 2012 (edited) :thumbup: I can't speak english very good. Sorry for using the google translator. I am creating a library "export.dll" for connecting the arduino directly to sim. :joystick: This is a beta, to test put the library in the bin folder of the sim. Export.rar is on attached file. In the export.lua: require("export") --load the library opencom()-- open the serial port and configure it has 115200 bps. example: opencom("COM7") opencom() requires the Arduino will send the word "conected" at startup to continue. Serial.print("conected "); See my arduino sketch. writecom() -- send data to the serial port example: writecom("HelloWorld") readcom() -- read the serial port example: print(readcom()) closecom() -- close the serial port My export.lua example: require("export") --load the library function LuaExportStart() opencom("COM7") --abrimos el puerto y esperamos a que el arduino envie el comando "conected" end function LuaExportBeforeNextFrame() command = readcom() -- leemos datos del puerto serie y si corresponde con down o up le mandamos al sim que suba o baje el tren de aterrizaje. if command == "down" then LoSetCommand(431) elseif command == "up" then LoSetCommand(430) end end function LuaExportAfterNextFrame() local altBar = LoGetAltitudeAboveSeaLevel() --leemos la altura del sim writecom(string.format("AltBar %2.fM.",altBar)) -- y la mandamos por el puerto serie end[/center] function LuaExportStop() closecom() --cerramos el puerto serie end My arduino sketch: #include <LiquidCrystal.h> LiquidCrystal lcd(8, 9, 4, 5, 6, 7); char caracter; byte i=0; char cadena[100]; int val = 0; void setup() { Serial.begin(115200); //Configuramos puerto serie lcd.begin(16, 2); lcd.clear(); lcd.print("Arduino OK"); Serial.print("conected "); //Enviamos conected por el puerto serie } void loop() { if(Serial.available()) // si hay algo en el puerto serie lo imprimimos por pantalla { caracter=Serial.read(); if (caracter == 10) { cadena[i++]=' '; i=0; if(!strcmp(cadena,"state")) { lcd.clear(); lcd.setCursor(0, 0); lcd.print("Conected to DCS"); } else { lcd.clear(); lcd.setCursor(0, 0); lcd.print(cadena); } } else cadena[i++]=caracter; } val = analogRead(0); //leemos los botones del arduinop y mandamos el comando por el puerto serie if (val > 75 && val < 200) { Serial.print("up"); delay(200); } if (val > 200 && val < 350) { Serial.print("down"); delay(200); } } :pilotfly:export.rar Edited August 8, 2012 by blackleg
Duckling Posted August 8, 2012 Posted August 8, 2012 Thanks for sharing your code , blackleg. Having a Arduino at hand but yet to be put into work. Your post will make it a lot easier Cheers Gus - - - -
Weltensegler Posted August 8, 2012 Posted August 8, 2012 Nice! good job! But format Text left side please :) its really hard to read! It looks like you call a lot of functions that I don't see defined in this code nor referencing another file. Just curious... are they all pre-defined in the syntax? 4790K@4,6Ghz | EVGA Z97 Classified | 32GB @ 2400Mhz | Titan X hydro copper| SSD 850 PRO ____________________________________ Moments in DCS: --> https://www.youtube.com/user/weltensegLA --> WELD's cockpit: --> http://forums.eagle.ru/showthread.php?t=92274
blackleg Posted August 8, 2012 Author Posted August 8, 2012 Nice! good job! But format Text left side please :) its really hard to read! It looks like you call a lot of functions that I don't see defined in this code nor referencing another file. Just curious... are they all pre-defined in the syntax? That functions?
blackleg Posted August 10, 2012 Author Posted August 10, 2012 (edited) New version of the library. :thumbup: And this not work.:chair: Edited August 10, 2012 by blackleg The new library not work.
blackleg Posted August 14, 2012 Author Posted August 14, 2012 New version for testing. :thumbup:export.rar
Waxi Posted August 15, 2012 Posted August 15, 2012 (edited) Thanks for sharing. This is very interesting since I never managed to get Lua to talk to the serial port and my Arduinos. I will definitely look into your stuff. Edited August 15, 2012 by Waxi
ED Team BIGNEWY Posted August 18, 2012 ED Team Posted August 18, 2012 great stuff I am currently working on a ufc and caution panel using Arduino, I will keep an eye on this thread, very interesting stuff. thanks for sharing Forum rules - DCS Crashing? Try this first - Cleanup and Repair - Discord BIGNEWY#8703 - Youtube - Patch Status Windows 11, NVIDIA MSI RTX 3090, Intel® i9-10900K 3.70GHz, 5.30GHz Turbo, Corsair Hydro Series H150i Pro, 64GB DDR @3200, ASUS ROG Strix Z490-F Gaming, PIMAX Crystal
Recommended Posts