Arduino bundle for TextMate

xSmurf, could you upload the textmate bundle somewhere? I am still in the evalutation period of textmate but it seems asa very good editor to me. Finally leaving vim behind me. (outside a terminal that is)
I just started using the arduino programmer as described on tinker.it. I expected that this programmer with textmate will make programming a lot easier.

I tried to compile LCD4bitexample (from the playground) with the makefile from Oliver. But there are some errors:

applet/LCD4BitExample.cpp:4:21: error: LCD4Bit.h: No such file or directory
applet/LCD4BitExample.cpp:7: error: 'LCD4Bit' does not name a type
applet/LCD4BitExample.cpp: In function 'void setup()':
applet/LCD4BitExample.cpp:16: error: 'lcd' was not declared in this scope
applet/LCD4BitExample.cpp: In function 'void loop()':
applet/LCD4BitExample.cpp:28: error: 'lcd' was not declared in this scope
make: *** [applet/LCD4BitExample.elf] Error 1

It seems that LCD4Bit.h can not be found. What do I have to change so it will be found? I expect that all additional libraries will not be found.

For a quick "hack" you need to add LCD4Bit.cpp to the CXXSRC variable in the makefile.
Then in the .pde it must read #include "LCD4Bit.h" (no < >) to reference the lib as a local file. The last step is to put the LCD4Bit.h/.cpp in the same directory as the makefile and the .pde. Then it compiles - at least in my case. :wink:

I'm still searching for a nice setup, to include the arduino libs nicely in the makefile. Can anybody help?
When it's more polished I'll hopefully find time to do a Playground entry.

For a quick "hack" you need to add LCD4Bit.cpp to the CXXSRC variable in the makefile.
Then in the .pde it must read #include "LCD4Bit.h" (no < >) to reference the lib as a local file. The last step is to put the LCD4Bit.h/.cpp in the same directory as the makefile and the .pde. Then it compiles - at least in my case. :wink:

I see, but this is going to a mess after a while. If I change something in the LCD4Bit.cpp, where do I change it? I assume this has to be local, in the directory where the pde is? If you start a new program with the modified library you have to copy the library files to the new program directory.

You are right, but this is no limitation of makefiles. It's only a question of proper usage. We need to use the -I switches for includes right but I forgot how it's done...

regarding your improved upload process: keep in mind you can allways change preferences.txt if you wan't to change the upload programmer. So there's no need to skip the Arduino IDE only to use a different programmer.

Slowly it is all coming back, -I, I can recall that, from a very long time ago.

I added an arduinolibs parameter, so, that is a bit easier to add, for instance:

CXXSRC = $(ARDUINO)/HardwareSerial.cpp $(ARDUINO)/WRandom.cpp $(ARDUINOLIBS)/LCD4Bit/LCD4Bit.cpp

And I made a symbolic link to LCD4Bit.h in the sketch directory. After that I changed the avrdude config to work with my programmer. Now it works perfectly. So, command-R and command-U work, this is very nice for lots of uploads, it works very quick.

Yeah, it's really quick. I'm happy someone else also finds it usefull!

If you add -I$(ARDUINOLIBS)/LCD4Bit to CXXINCS it should recognize the lib w/o a symbolic link. But I think you need to write again in #include <LCD4Bit.h> (with <>).

There must be a nice way to include all libraries from "/lib/target/librariers" without explicitly menitioning them. Similar like in the line that starts with "@for i in $(OBJ)". This is real makefile science...

The current "command line" instructions mention installing "real" avr-gcc. If you've already installed arduino to get the libraries and source modules needed, you already have a copy of avr-gcc that's certainly complete enough to compile arduino sketches, and the makefile can make that invisible to the users. I have (in the makefile from the wiki):

# Program settings
CC =  /Downloads/arduino-0008/tools/avr/bin/avr-gcc
CXX = /Downloads/arduino-0008/tools/avr/bin/avr-g++
OBJCOPY = /Downloads/arduino-0008/tools/avr/bin/avr-objcopy
OBJDUMP = /Downloads/arduino-0008/tools/avr/bin/avr-objdump
SIZE = /Downloads/arduino-0008/tools/avr/bin/avr-size
NM = /Downloads/arduino-0008/tools/avr/bin/avr-nm
AVRDUDE = /Downloads/arduino-0008/tools/avr/bin/avrdude

shure, the makfile that comes in arduino-0009/lib/tragets/arduino also uses local avr-gcc.
This is why I changed it in my makefile (see rapidshare link http://rapidshare.com/files/51829818/Arduino_Makfile_Textmate_Bundle.zip.html) to reference the $(AVR_TOOLS_PATH) dir inside an arduino installation.

I am still having trouble with the Makefile and libraries. The LCD4Bit works with the -I mentioned some posts above. But the twi lib doesn't work. In Wire.cpp I changed #include "twi.h" to #include "utility/twi.h" (line 24), this gets me a little bit further but it still doesn't compile. This is the make output:

applet/core.a(Wire.o): In function `TwoWire::begin()':
Wire.cpp:(.text+0x38): undefined reference to `twi_init'
applet/core.a(Wire.o): In function `TwoWire::begin(unsigned char)':
Wire.cpp:(.text+0x44): undefined reference to `twi_setAddress'
Wire.cpp:(.text+0x4a): undefined reference to `twi_attachSlaveTxEvent'
Wire.cpp:(.text+0x50): undefined reference to `twi_attachSlaveRxEvent'
applet/core.a(Wire.o): In function `TwoWire::requestFrom(unsigned char, unsigned char)':
Wire.cpp:(.text+0x76): undefined reference to `twi_readFrom'
applet/core.a(Wire.o): In function `TwoWire::endTransmission()':
Wire.cpp:(.text+0xae): undefined reference to `twi_writeTo'
applet/core.a(Wire.o): In function `TwoWire::send(unsigned char)':
Wire.cpp:(.text+0x10c): undefined reference to `twi_transmit'
applet/core.a(Wire.o): In function `TwoWire::send(unsigned char*, unsigned char)':
Wire.cpp:(.text+0x15c): undefined reference to `twi_transmit'
make: *** [applet/i2c_test.elf] Error 1

I made a very simple example:

#include <Wire.h>
void setup() 
{ 
      
      
      Wire.begin();
      
      Wire.beginTransmission(0x1D);
      Wire.send(0x20);
      Wire.send(0x87);
      Wire.endTransmission();
      
}
void loop()
{
}

This compiles with the arduino IDE. The modifications to the makefile:

ARDUINO = $(INSTALL_DIR)/lib/targets/arduino
ARDUINOLIBS = $(INSTALL_DIR)/lib/targets/libraries
AVR_TOOLS_PATH = $(INSTALL_DIR)/tools/avr/bin
SRC =  $(ARDUINO)/pins_arduino.c $(ARDUINO)/wiring.c \
$(ARDUINO)/wiring_analog.c $(ARDUINO)/wiring_digital.c \
$(ARDUINO)/wiring_pulse.c $(ARDUINO)/wiring_serial.c \
$(ARDUINO)/wiring_shift.c $(ARDUINO)/WInterrupts.c
CXXSRC = $(ARDUINO)/HardwareSerial.cpp $(ARDUINO)/WRandom.cpp \
$(ARDUINOLIBS)/Wire/Wire.cpp
FORMAT = ihex


# Name of this Makefile (used for "make depend").
MAKEFILE = Makefile

# Debugging format.
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
DEBUG = stabs

OPT = s

# Place -D or -U options here
CDEFS = -DF_CPU=$(F_CPU)
CXXDEFS = -DF_CPU=$(F_CPU)

# Place -I options here
CINCS = -I$(ARDUINO) -I$(ARDUINOLIBS)/Wire -I$(INSTALL_DIR)/lib/targets/wiring 
CXXINCS = -I$(ARDUINO)

You need to add twi.c to your SRC variable (e.g. $(ARDUINOLIBS)/Wire/utility/twi.c).

Great! It works!!

If anyone is using TextMate to write straight C code using avr glibc, this might help:

http://www.rahji.com/wordpress/2007/09/27/textmate-syntax-highlighting-for-avr-libc/

Good luck,
rob

Neat! Thank Rahji! I've got to try that out :smiley:

hi all, just got my arduino today! before finding this thread (which i admit i only skimmed over) i added a 'run in arduino' command to my the processing textmate bundle that i got through the getbundle bundle. the 'run in processing' command needed to be changed as per this thread:
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Collaboration;action=di splay;num=1174403295

so i just copied the 'run in processing' command but changed the code to this:
osascript <<EOF
tell application "Arduino 09" to run
tell application "Arduino 09" to activate
tell application "Arduino 09" to open POSIX file "${TM_FILEPATH}"
delay 1
tell application "System Events" to tell process "Arduino"
keystroke "u" using command down
end tell
EOF

this works but it would be great if someone came up with an arduino bundle (just by copying the processing bundle) for getbundle so that all the syntax highlighting would be correct. i don't know how but maybe if no one beats me to it i'll get around to it...

I've been working on a TextMate bundle. I just updated it to support the -10 release. (There are lots of warnings generated by the compiler, which I'd be happy to fix and check in.

Feedback welcome.

You can download from this blog post:
http://www.ooeygui.com/?p=46

thanks - look forward to trying it out - but the download link on your page is wrong. need to remove /wp-admin form the url

I'd be willing to check the code into a public Arduino repository, so we can get other people hacking on it. So far, I've got the following features implemented:

Menu to Choose the microcontroller architecture - Atmega 8, Atmega 168, and the Make Controller (forthcoming).
Menu item to Compile and upload to the Microcontroller
Menu to Show a Serial Monitor.

The serial monitor is a sepaate binary which reads from the serial port and outputs using the OSX terminal. This does mean you can use ANSI codes - I hope to add support to the serial library for making this easier.

The plugin also includes an output window which collects the output from the compiler and uploader.

Future enhancements:

  • User specified makefile (something that gets included into the build process instead of manually walking the tree).
  • Make controller support.
  • Hot Keys for building
  • Don't leak so much
  • Ability to specify upload port
  • Multiple controller support.
  • Non-blocking calls to external binaries

NOTE: This was built on an Intel machine running Leopard. It has not been tested on Tiger or PowerPC; Would be interested to know how it works.

Good luck, and enjoy!

(Thanks for the note about the broken link. Wordpress has been messing with my posts.)

w00t, I'll be trying this right away! :smiley:

It'd be nice if it was in the repository :slight_smile:

Here is another Textmate Arduino bundle I've done this afternoon:

Once installed, you just have to press Command+Shift+A to make and upload your program on the Arduino.

Be sure your Arduino program is installed in /Applications/arduino-0011/

It's working with Blink.pde, I'm not sure yet it'd be working with something else, but as I'll use it a lot this week our Reprap project - http://www.reprap.org - you'll be sure to see some updates on the repository.
If you have some patches, you can clone/fork the repository, I'll be glad to add your particpation in this bundle :slight_smile: