Recent

Author Topic: Arduino  (Read 7009 times)

clemmi

  • Jr. Member
  • **
  • Posts: 54
Arduino
« on: May 15, 2015, 07:45:28 pm »
I want to control an Arduino mega board using Lazarus GUI.
I installed the 5dpo package in Lazarus.
All links that I found with references how to use it or sample codes are not active now.

Do someone have a simple sample code (Ardino and Lazarus) to send data back and ford?
I'm familiar in programming with both systems, Lazarus and Arduino, but a simple code will get me started with this project.
Thanks!

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: Arduino
« Reply #1 on: May 16, 2015, 01:07:19 am »
Hello,
look at  here

Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

parcel

  • Full Member
  • ***
  • Posts: 143
Re: Arduino
« Reply #2 on: May 16, 2015, 01:26:28 am »
If serial access is not good for your project, there is enc28j60 ethernet board.

It make simple webserver in arduino.

I made simple remote via ethernet. It works good :)

Code: [Select]
/* ethercard and irDA remote control */

#include <EtherCard.h>
#include <IRremote.h>

//#define IR_ONLY
#ifndef IR_ONLY
// ethernet interface mac address
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x35 };
// ethernet interface ip address
static byte myip[] = { 192,168,1,200 };
// gateway ip address
static byte gwip[] = { 192,168,1,1 };

byte Ethernet::buffer[700];
static long timer;
BufferFiller bfill;
byte irdata[104];
#endif

bool success_dhcp=false;

IRsend irsend;
#define IR_NORECV
#ifndef IR_NORECV
int recv_pin=5;
IRrecv irrecv(recv_pin);
decode_results results;
#endif
long lg_on=0x20df10ef;

char* hextobyte(char *str,byte *ret)
{
  *ret=0;
  byte cnt=0;
  while((str!=NULL)&&(*str!=0)&&(*str>32)) {
    if((*str>='0')&&(*str<='9')) {
      *ret+=*str-'0';
    } else
    if((*str>='a')&&(*str<='f')) {
      *ret+=10+(*str-'a');
    } else
    if((*str>='A')&&(*str<='F')) {
      *ret+=10+(*str-'A');
    } else {
      return NULL;
    }
    str++;
    cnt++;
    if(cnt==2) break;
    if((*str!=0)&&(*str>32)) *ret<<=4;
  }
  return str;
}

void ethernet_setip() {
    #ifndef IR_ONLY
    if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
    Serial.println( "Failed to access Ethernet controller");
 
    #define STATIC_IP
    #ifndef STATIC_IP
    success_dhcp=ether.dhcpSetup();
    #endif
    if(success_dhcp) {
      ether.printIp("My IP: ", ether.myip);
      // ether.printIp("Netmask: ", ether.mymask);
      ether.printIp("GW IP: ", ether.gwip);
      ether.printIp("DNS IP: ", ether.dnsip);     
      Serial.println("success dhcp");
    } else {
       // set ip address 192.168.1.200
       ether.staticSetup(myip,gwip);
       success_dhcp=true;
       Serial.println("static ip address : 192.168.1.200");
    }
    #endif
}

void setup () {
  Serial.begin(9600);
  #ifndef IR_NORECV
  irrecv.enableIRIn();
  #endif
 
  ethernet_setip();
  //irsend.sendNEC(lg_on,32);
}

const char http_OK[] PROGMEM =
    "HTTP/1.0 200 OK\r\n"
    "Content-Type: text/html\r\n"
    "Pragma: no-cache\r\n\r\n";

const char http_Found[] PROGMEM =
    "HTTP/1.0 302 Found\r\n"
    "Location: /\r\n\r\n";

const char http_Unauthorized[] PROGMEM =
    "HTTP/1.0 401 Unauthorized\r\n"
    "Content-Type: text/html\r\n\r\n"
    "<h1>401 Unauthorized</h1>";

void loop() {
   // working
    #ifndef IR_NORECV
    if(irrecv.decode(&results)) {
      if(results.decode_type==LG) Serial.println("LG");
      Serial.println(results.value,HEX);
      irrecv.resume();
    }
    #else
    word len=ether.packetReceive();
    word pos=ether.packetLoop(len);
    char* wpos;
    if(pos) {
      bfill=ether.tcpOffset();
      char *data=(char*)Ethernet::buffer+pos;
      Serial.println(data);
      if(strncmp("GET /",data,5)!=0) {
        bfill.emit_p(http_Unauthorized);       
      } else {
        data+=5;
        if(data[0]==' ') {
          bfill.emit_p(http_OK);
          bfill.emit_p(PSTR("Arduino IRRemote server"));
        } else
        if(NULL!=(wpos=strstr(data,"q?data="))) {         
          Serial.println("start parsing");
          //Serial.println(wpos);
          byte byte2;
          wpos+=7;
          wpos=hextobyte(wpos,&byte2); // type
          irdata[0]=byte2;
          wpos=hextobyte(wpos,&byte2);  // bits
          irdata[1]=byte2;
          wpos=hextobyte(wpos,&byte2);  // repeat
          irdata[2]=byte2;
          wpos=hextobyte(wpos,&byte2);  // hz lo
          irdata[3]=byte2;
          wpos=hextobyte(wpos,&byte2);  // hz hi
          irdata[4]=byte2;       
          byte dpos=5;
          while((wpos!=NULL)&&(*wpos!=0)&&(*wpos>32)) {
            wpos=hextobyte(wpos,&byte2);
            irdata[dpos]=byte2;
            dpos++;
            if(dpos>=100) break;
          }
          irdata[dpos]=0;
          Serial.println("finish parsing");
          // send data if valid.
          char codetype[11];
          if(dpos>5) {
            switch(irdata[0]) {
              case 1: irsend.sendNEC(*((long *)&irdata[5]),irdata[1]); strncpy(codetype,"NEC",10); break;
              case 2: irsend.sendSony(*((long *)&irdata[5]),irdata[1]); strncpy(codetype,"Sony",10); break;
              case 3: irsend.sendRC5(*((long *)&irdata[5]),irdata[1]); strncpy(codetype,"RC5",10); break;
              case 4: irsend.sendRC6(*((long *)&irdata[5]),irdata[1]); strncpy(codetype,"RC6",10); break;
              case 5: irsend.sendDISH(*((long *)&irdata[5]),irdata[1]); strncpy(codetype,"DISH",10); break;
              case 6: irsend.sendSharp(*((long *)&irdata[5]),irdata[1]); strncpy(codetype,"Sharp",10); break;
              case 7: irsend.sendPanasonic(*((int *)&irdata[3]),*((long*)&irdata[5])); strncpy(codetype,"Panasonic",10); break; // word address, long data
              case 8: irsend.sendJVC(*((long *)&irdata[5]),irdata[1],irdata[2]); strncpy(codetype,"JVC",10); break;          // long data, repeat
              case 9: irsend.sendSAMSUNG(*((long *)&irdata[5]),irdata[1]); strncpy(codetype,"SAMSUNG",10); break;
              default: irsend.sendRaw((unsigned int*)&irdata[5],irdata[2],*(unsigned int*)&irdata[3]); strncpy(codetype,"Raw",10); break;   // word* data, len, hz | hz, data1, data2, ... | len = repeat
            }
          }
          bfill.emit_p(http_OK);
          char temp[10];
          bfill.emit_p(PSTR("\nIRRemote parsed : $D / type:$S, bits:$D, repeat(len):$D, address(hz):$D, long code:$S\n"), dpos, codetype, irdata[1], irdata[2], *(unsigned int*)&irdata[3],ultoa(*((long *)&irdata[5]),temp,16));
          // dump
          for(int i=5; i<dpos; i++) {
            bfill.emit_p(PSTR("$H"),irdata[i]);
          }
        } else {
          bfill.emit_p(http_Unauthorized);
        }
      }
      ether.httpServerReply(bfill.position());
    }
    #endif
}

https://github.com/jcw/ethercard
https://github.com/shirriff/Arduino-IRremote

Gizmo

  • Hero Member
  • *****
  • Posts: 831
Re: Arduino
« Reply #3 on: June 30, 2015, 03:34:36 pm »

seaton

  • New Member
  • *
  • Posts: 48
Re: Arduino
« Reply #4 on: July 08, 2015, 08:32:51 am »
I use the uFirmata library for the arduino which is a light weight firmata library and rolled my own firmarta unit for Lazarus

Explore the links below to see how it works, Apologies for the lack of documentation, but if you have any questions let me know.  It was only recently moved over from google code and none of the wiki is online.

Only downside with firmarta protocol is it's not human readable, i.e. it's in binary so is more efficient, but harder to debug.

Lazarus Side:
https://github.com/madeinoz67/rallylog.remote   

If you;'re wondering why there are no com port config/connect/disconnect in the gui, I made things easier for the end user by using some of the FTDI DLL functions and rolled my own FTDI wrapper to automatically detect and connect to the com port once a device is plugged in (windows only)

Arduino side:
https://github.com/madeinoz67/rallylog.firmware   

In particular look at the Rallylog directory for the final implementation of the firmware.
« Last Edit: July 10, 2015, 05:07:04 am by seaton »

 

TinyPortal © 2005-2018