Pages: [1]   Go Down
Author Topic: Importing Arduino sketches to Eclipse (C/C++)  (Read 1151 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello I have this sketch:

Code:
int incomingByte = 0;   // for incoming serial data

void setup() {
  pinMode(13,OUTPUT);
        Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
}

void loop() {

        // send data only when you receive data:
        if (Serial.available() > 0) {
                // read the incoming byte:
                incomingByte = Serial.read();

                // say what you got:
                Serial.print("I received: ");
                Serial.println(incomingByte, DEC);
               
               
                if(incomingByte == 49){
                  digitalWrite(13,HIGH);
                }else if(incomingByte == 48){
                 digitalWrite(13,LOW);
                }
                 
        }
}
that I would like to import into my Eclipse C/C++ project. Should I use external libraries such as CSerial or is there any way I can move it in? I have read the http://todbot.com/blog/2013/04/29/arduino-serial-updated/ but I still don't get what I am suppose to do to get the same results. Thanks.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8970
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Does this work if you link it with the Arduino core and libraries? 

If you don't want to use the Arduino libraries you will need to find replacements for pinMode(), Serial, and digitalWrite().

Code:
#include <Arduino.h>

int incomingByte = 0;   // for incoming serial data

void setup() {
  pinMode(13,OUTPUT);
        Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
}

void loop() {

        // send data only when you receive data:
        if (Serial.available() > 0) {
                // read the incoming byte:
                incomingByte = Serial.read();

                // say what you got:
                Serial.print("I received: ");
                Serial.println(incomingByte, DEC);
               
               
                if(incomingByte == 49){
                  digitalWrite(13,HIGH);
                }else if(incomingByte == 48){
                 digitalWrite(13,LOW);
                }
                 
        }
}
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Then is it okay if I do something like this?
1) Run the code first from the Arduino IDE to establish the connection
2) Run the "digitalWrite" statement from my C/C++ code within another running app on my Desktop?

Is that okay?
Thanks~
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8970
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

2) Run the "digitalWrite" statement from my C/C++ code within another running app on my Desktop?
I don't understand what you mean by this.

To compile an Arduino sketch outside of the Arduino IDE you need to compile and link the Arduino core libraries, like this:
Quote
Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega2560 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -IArduino/hardware/arduino/cores/arduino -IArduino/hardware/arduino/variants/mega build/sketch_may18a.cpp -o build/sketch_may18a.cpp.o

Arduino/hardware/tools/avr/bin/avr-gcc -c -g -Os -Wall -ffunction-sections -fdata-sections -mmcu=atmega2560 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -IArduino/hardware/arduino/cores/arduino -IArduino/hardware/arduino/variants/mega Arduino/hardware/arduino/cores/arduino/WInterrupts.c -o build/WInterrupts.c.o

Arduino/hardware/tools/avr/bin/avr-gcc -c -g -Os -Wall -ffunction-sections -fdata-sections -mmcu=atmega2560 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -IArduino/hardware/arduino/cores/arduino -IArduino/hardware/arduino/variants/mega Arduino/hardware/arduino/cores/arduino/wiring.c -o build/wiring.c.o

Arduino/hardware/tools/avr/bin/avr-gcc -c -g -Os -Wall -ffunction-sections -fdata-sections -mmcu=atmega2560 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -IArduino/hardware/arduino/cores/arduino -IArduino/hardware/arduino/variants/mega Arduino/hardware/arduino/cores/arduino/wiring_analog.c -o build/wiring_analog.c.o

Arduino/hardware/tools/avr/bin/avr-gcc -c -g -Os -Wall -ffunction-sections -fdata-sections -mmcu=atmega2560 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -IArduino/hardware/arduino/cores/arduino -IArduino/hardware/arduino/variants/mega Arduino/hardware/arduino/cores/arduino/wiring_digital.c -o build/wiring_digital.c.o

Arduino/hardware/tools/avr/bin/avr-gcc -c -g -Os -Wall -ffunction-sections -fdata-sections -mmcu=atmega2560 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -IArduino/hardware/arduino/cores/arduino -IArduino/hardware/arduino/variants/mega Arduino/hardware/arduino/cores/arduino/wiring_pulse.c -o build/wiring_pulse.c.o

Arduino/hardware/tools/avr/bin/avr-gcc -c -g -Os -Wall -ffunction-sections -fdata-sections -mmcu=atmega2560 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -IArduino/hardware/arduino/cores/arduino -IArduino/hardware/arduino/variants/mega Arduino/hardware/arduino/cores/arduino/wiring_shift.c -o build/wiring_shift.c.o

Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega2560 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -IArduino/hardware/arduino/cores/arduino -IArduino/hardware/arduino/variants/mega Arduino/hardware/arduino/cores/arduino/CDC.cpp -o build/CDC.cpp.o

Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega2560 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -IArduino/hardware/arduino/cores/arduino -IArduino/hardware/arduino/variants/mega Arduino/hardware/arduino/cores/arduino/HardwareSerial.cpp -o build/HardwareSerial.cpp.o

Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega2560 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -IArduino/hardware/arduino/cores/arduino -IArduino/hardware/arduino/variants/mega Arduino/hardware/arduino/cores/arduino/HID.cpp -o build/HID.cpp.o

Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega2560 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -IArduino/hardware/arduino/cores/arduino -IArduino/hardware/arduino/variants/mega Arduino/hardware/arduino/cores/arduino/IPAddress.cpp -o build/IPAddress.cpp.o

Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega2560 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -IArduino/hardware/arduino/cores/arduino -IArduino/hardware/arduino/variants/mega Arduino/hardware/arduino/cores/arduino/main.cpp -o build/main.cpp.o

Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega2560 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -IArduino/hardware/arduino/cores/arduino -IArduino/hardware/arduino/variants/mega Arduino/hardware/arduino/cores/arduino/new.cpp -o build/new.cpp.o

Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega2560 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -IArduino/hardware/arduino/cores/arduino -IArduino/hardware/arduino/variants/mega Arduino/hardware/arduino/cores/arduino/Print.cpp -o build/Print.cpp.o

Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega2560 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -IArduino/hardware/arduino/cores/arduino -IArduino/hardware/arduino/variants/mega Arduino/hardware/arduino/cores/arduino/Stream.cpp -o build/Stream.cpp.o

Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega2560 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -IArduino/hardware/arduino/cores/arduino -IArduino/hardware/arduino/variants/mega Arduino/hardware/arduino/cores/arduino/Tone.cpp -o build/Tone.cpp.o

Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega2560 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -IArduino/hardware/arduino/cores/arduino -IArduino/hardware/arduino/variants/mega Arduino/hardware/arduino/cores/arduino/USBCore.cpp -o build/USBCore.cpp.o

Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega2560 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -IArduino/hardware/arduino/cores/arduino -IArduino/hardware/arduino/variants/mega Arduino/hardware/arduino/cores/arduino/WMath.cpp -o build/WMath.cpp.o

Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega2560 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -IArduino/hardware/arduino/cores/arduino -IArduino/hardware/arduino/variants/mega Arduino/hardware/arduino/cores/arduino/WString.cpp -o build/WString.cpp.o

Arduino/hardware/tools/avr/bin/avr-ar rcs build/core.a build/WInterrupts.c.o

Arduino/hardware/tools/avr/bin/avr-ar rcs build/core.a build/wiring.c.o

Arduino/hardware/tools/avr/bin/avr-ar rcs build/core.a build/wiring_analog.c.o

Arduino/hardware/tools/avr/bin/avr-ar rcs build/core.a build/wiring_digital.c.o

Arduino/hardware/tools/avr/bin/avr-ar rcs build/core.a build/wiring_pulse.c.o

Arduino/hardware/tools/avr/bin/avr-ar rcs build/core.a build/wiring_shift.c.o

Arduino/hardware/tools/avr/bin/avr-ar rcs build/core.a build/CDC.cpp.o

Arduino/hardware/tools/avr/bin/avr-ar rcs build/core.a build/HardwareSerial.cpp.o

Arduino/hardware/tools/avr/bin/avr-ar rcs build/core.a build/HID.cpp.o

Arduino/hardware/tools/avr/bin/avr-ar rcs build/core.a build/IPAddress.cpp.o

Arduino/hardware/tools/avr/bin/avr-ar rcs build/core.a build/main.cpp.o

Arduino/hardware/tools/avr/bin/avr-ar rcs build/core.a build/new.cpp.o

Arduino/hardware/tools/avr/bin/avr-ar rcs build/core.a build/Print.cpp.o

Arduino/hardware/tools/avr/bin/avr-ar rcs build/core.a build/Stream.cpp.o

Arduino/hardware/tools/avr/bin/avr-ar rcs build/core.a build/Tone.cpp.o

Arduino/hardware/tools/avr/bin/avr-ar rcs build/core.a build/USBCore.cpp.o

Arduino/hardware/tools/avr/bin/avr-ar rcs build/core.a build/WMath.cpp.o

Arduino/hardware/tools/avr/bin/avr-ar rcs build/core.a build/WString.cpp.o

Arduino/hardware/tools/avr/bin/avr-gcc -Os -Wl,--gc-sections,--relax -mmcu=atmega2560 -o build/sketch_may18a.cpp.elf build/sketch_may18a.cpp.o build/core.a -Lbuild/ -lm

Arduino/hardware/tools/avr/bin/avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 build/sketch_may18a.cpp.elf build/sketch_may18a.cpp.eep

Arduino/hardware/tools/avr/bin/avr-objcopy -O ihex -R .eeprom build/sketch_may18a.cpp.elf build/sketch_may18a.cpp.hex
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Earth
Offline Offline
Edison Member
*
Karma: 53
Posts: 1882
My browser no longer is binding static IP, Floating is the way to go.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

use Eclipse plugin AVR-eclipse?

http://playground.arduino.cc/Code/Eclipse

http://www.baeyens.it/eclipse/
Logged

Offline Offline
Sr. Member
****
Karma: 7
Posts: 292
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Or in fact much better yet, use the Arduino Eclipse plugin. Newest version is 2.1.0.4.
Installation instructions are here under "Teensy, Arduino, Etc." :

trippylighting.com
Logged


Pages: [1]   Go Up
Jump to: