Difference between revisions of "Arduino/es"
m (Fixed syntax highlighting) |
|||
(3 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{Arduino}} | ||
+ | |||
Este artículo describe la manera de comunicar tu aplicación Lazarus/FPC con [https://en.wikipedia.org/wiki/Arduino Placas Arduino]. | Este artículo describe la manera de comunicar tu aplicación Lazarus/FPC con [https://en.wikipedia.org/wiki/Arduino Placas Arduino]. | ||
Esto abre un mundo completamente nuevo de sensores y actuadores físicos inteligentes para monitorización, control y adquisición de datos. | Esto abre un mundo completamente nuevo de sensores y actuadores físicos inteligentes para monitorización, control y adquisición de datos. | ||
Line 13: | Line 15: | ||
==== Minimal Lazarus Synaser serial example ==== | ==== Minimal Lazarus Synaser serial example ==== | ||
− | We will use [http://synapse.ararat.cz/doc/help/synaser.html Synaser] from [http://www.ararat.cz/synapse/doku.php Synapse library] in this example. Create Lazarus application with one form and two buttons. Include Synaser unit and add [[ | + | We will use [http://synapse.ararat.cz/doc/help/synaser.html Synaser] from [http://www.ararat.cz/synapse/doku.php Synapse library] in this example. Create Lazarus application with one form and two buttons. Include Synaser unit and add [[Synapse|Synapse package]] as a new requirement to your project. In OnClick event of both buttons put something like this: |
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
procedure TForm1.Button1Click(Sender: TObject); | procedure TForm1.Button1Click(Sender: TObject); | ||
var | var | ||
Line 37: | Line 39: | ||
==== Minimal Arduino C sketch serial example ==== | ==== Minimal Arduino C sketch serial example ==== | ||
You can follow [http://www.chrisbrand.co.za/2013/06/30/arduino-serial-port/ this] nice step by step tutorial. In short, you need to add a led with proper resistor to your input pin 13, compile this sketch in your [https://www.arduino.cc/en/Main/Software Arduino IDE], and download it to your board: | You can follow [http://www.chrisbrand.co.za/2013/06/30/arduino-serial-port/ this] nice step by step tutorial. In short, you need to add a led with proper resistor to your input pin 13, compile this sketch in your [https://www.arduino.cc/en/Main/Software Arduino IDE], and download it to your board: | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang=cpp> |
int led = 13; // Pin 13 | int led = 13; // Pin 13 | ||
Line 106: | Line 108: | ||
[https://bigdanzblog.wordpress.com/2014/11/19/tcp-communications-between-a-pc-and-an-arduino-nano-using-lazarus-free-pascal/ FPC application talking to Arduino Nano over TCP] | [https://bigdanzblog.wordpress.com/2014/11/19/tcp-communications-between-a-pc-and-an-arduino-nano-using-lazarus-free-pascal/ FPC application talking to Arduino Nano over TCP] | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− |
Latest revision as of 08:32, 9 February 2020
│
Deutsch (de) │
English (en) │
español (es) │
Este artículo describe la manera de comunicar tu aplicación Lazarus/FPC con Placas Arduino. Esto abre un mundo completamente nuevo de sensores y actuadores físicos inteligentes para monitorización, control y adquisición de datos.
Comunicación serie
Aquí se muestra como comunicar con tu placa a través del canal de comunicación serie.
Lazarus side serial application
Existen varias posibilidades para comunicaciones serie en Lazarus/FPC.
Minimal Lazarus Synaser serial example
We will use Synaser from Synapse library in this example. Create Lazarus application with one form and two buttons. Include Synaser unit and add Synapse package as a new requirement to your project. In OnClick event of both buttons put something like this:
procedure TForm1.Button1Click(Sender: TObject);
var
ser: TBlockSerial;
begin
ser := TBlockSerial.Create;
try
ser.Connect('COM1'); // Escribe aquí el puerto COM asociado a la comunicación con Arduino(en linux es algo así como
'/dev/ttyUSB0')
Sleep(250);
ser.config(9600, 8, 'N', SB1, False, False); // Establecemos los parámetros para la conexión Serie.
ser.SendString('on'); // Enviamos la cadena 'on', El pulsador 2 debería tener aquí 'off'
finally
ser.free; // Liberamos los recursos tomados para TBlockSerial.
end;
end;
Arduino side serial application
You can program your Arduino in several languages.
Minimal Arduino C sketch serial example
You can follow this nice step by step tutorial. In short, you need to add a led with proper resistor to your input pin 13, compile this sketch in your Arduino IDE, and download it to your board:
int led = 13; // Pin 13
void setup()
{
pinMode(led, OUTPUT); // Set pin 13 as digital out
// Start up serial connection
Serial.begin(9600); // baud rate
Serial.flush();
}
void loop()
{
String input = "";
// Read any serial input
while (Serial.available() > 0)
{
input += (char) Serial.read(); // Read in one char at a time
delay(5); // Delay for 5 ms so the next char has time to be received
}
if (input == "on")
{
digitalWrite(led, HIGH); // on
}
else if (input == "off")
{
digitalWrite(led, LOW); // off
}
}
Minimal Arduino mikroPascal serial example
mikroPascal for AVR can be used to develop Arduino programs. TBD.
Minimal Arduino E-Lab AvrCo serial example
E-Lab AvrCo Multitasking Pascal can be used to develop Arduino programs. TBD.
Minimal Arduino FPC serial example
Efectivamente, tu placa Arduino 8-bit AVR [AVR Programming|puede ser programada con FPC]] también. TBD.
Comunicación Ethernet
Aquí mostramos como comunicar con la placa a través del canal de comunicación Ethernet.
Lazarus side ethernet application
TBD
Arduino side ethernet application
TBD
Resources
Forum topic that started this article
Raspberry Pi Lazarus application talking to Arduino over serial