Normally I use the IDE to program and upload my sketches, but now I have deployed the Arduino Nano v4.0 in a project connected to Raspbery Pi via USB/Serial. When I need to make a change or tweak the code, during development I unplugged the Nano from the RPi (because it is headless and has no GUI), plugged it in to my computer, compiled the sketch, then plugged it back into the Nano. Now that is in use, any change I have to make requires tearing down to get to it. I decided to switch to command line makefile/make and upload the sketch using RPi. The problem is, I attempt to compile and upload the exact same sketch as the IDE and the compile errors out.
It took a while, but I narrowed down the error to digitalPinToInterrupt not working. A quick search lead to not choosing the correct board for anyone experiencing the same problem. Which now leads me to believe I am choosing the wrong board in command line vs IDE.
The board I choose in IDE is Atmega328P (Old Bootloader). After looking through boards.txt, it seems that bootloader points to atmega/ATmegaBOOT_168_atmega328.hex. The option to choose that same board, however, is not in command line. Here is my make file:
vvarrior:
The board I choose in IDE is Atmega328P (Old Bootloader). After looking through boards.txt, it seems that bootloader points to atmega/ATmegaBOOT_168_atmega328.hex.
You're barking up the wrong tree. Your problem has absolutely nothing to do with the bootloader file.
vvarrior:
Can anyone suggest a fix to correct the problem?
Unlikely, because you haven't provided enough information. We would need to know more about the error and also the makefile.
I guess I came to that conclusion because the code is identical on both computers (windows/IDE and RPi/command line). The files are the same. the only difference is the implementation of how the .ino file is compiled. When the IDE compiles it, all code executes successfully and the correct data is outputted.
When I attempt to access the serial using RPi using python, I receive an error message (the reason why I am trying to compile/upload)... It looks like it got stuck the last time I compiled the sketch:
File "/home/pi/pypi/lib/sensors/__init__.py", line 106, in getSerial
ser = serial.Serial(port='/dev/ttyUSB0',baudrate=9600,timeout=1) # create new serial object
File "/usr/local/lib/python2.7/dist-packages/serial/serialutil.py", line 240, in __init__
self.open()
File "/usr/local/lib/python2.7/dist-packages/serial/serialposix.py", line 286, in open
self._update_dtr_state()
File "/usr/local/lib/python2.7/dist-packages/serial/serialposix.py", line 634, in _update_dtr_state
fcntl.ioctl(self.fd, TIOCMBIS, TIOCM_DTR_str)
IOError: [Errno 5] Input/output error
I posted the makefile... Is there something missing from the makefile? That is all of the code that's in there. The error messages displayed during the make process don't seem to be helpful. They point to different functions not being declared in the scope.
The first error is the following:
mkdir -p build-nano328
/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -x c++ -include Arduino.h -MMD -c -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=105 -D__PROG_TYPES_COMPAT__ -I/usr/share/arduino/hardware/arduino//cores/arduino -I/usr/share/arduino/hardware/arduino//variants/eightanaloginputs -I/usr/share/arduino/libraries/OneWire -I/usr/share/arduino/libraries/TemperatureControl -Wall -ffunction-sections -fdata-sections -Os -fpermissive -fno-exceptions -std=gnu++11 -fno-threadsafe-statics -flto sensors_passive.ino -o build-nano328/sensors_passive.ino.o
sensors_passive.ino: In function ‘void setup()’:
sensors_passive.ino:61:22: error: ‘flowCount’ was not declared in this scope
attachInterrupt(0, flowCount, FALLING);
^
../Arduino.mk:1251: recipe for target 'build-nano328/sensors_passive.ino.o' failed
make: *** [build-nano328/sensors_passive.ino.o] Error 1
The sketch compiles with attachInterrupt is commented out but errors when I remove the comment.
vvarrior:
I posted the makefile... Is there something missing from the makefile? That is all of the code that's in there.
OK, but the important stuff is in Arduino.mk. I'm guessing this is something you found online so it might be helpful to post a link to it.
vvarrior:
sensors_passive.ino: In function ‘void setup()’:
sensors_passive.ino:61:22: error: ‘flowCount’ was not declared in this scope
attachInterrupt(0, flowCount, FALLING);
Please post your sketch. The error indicates to me that the problem is with the flowCount function prototype. The Arduino IDE automatically generates prototypes for functions in .ino files when you haven't provided them in your code. Alternatives like the Arduino makefiles may make an attempt to do this but not do it as well (it's very complicated) or else they might not even offer any prototype generation capabilities.
I actually think the version of arduino on my RPi might be outdate (1.0.5) but i'm having trouble locating where the newest ardunio-mk and arduino-core. I've found and have installed what I think is newest version. I will at it in the morning and follow up.
Yes, 1.0.5 is horribly outdated. If Arduino.mk is using the Arduino IDE then that could be the cause of the function prototype generation failure since that has been improved in the years since the release of Arduino IDE 1.0.5.
You should never use apt-get or any other package manager to install the Arduino IDE because they always have outdated and/or randomly modified versions of the Arduino IDE. You should always use the official Arduino IDE downloaded from:
In the case of the RPi, you will want the "Linux ARM" download.
First off, I really appreciate your help.
Second, seems like I'm missing something in the makefile... Here is what I have done so far (removed arduino, arduino-core, arduino-mk packages, got the newest arduino-1.8.6 and Arduino-Maker and installed, changed sketch makefile and ran make again):
cd ~/arduino/sketchbook/sketch_test
make
(results removed)
avr-g++: error: missing device or architecture after '-mmcu='
/home/pi/Applications/Arduino-Makefile/Arduino.mk:1310: recipe for target 'build-nano/sensors_passive.ino.o' failed
make: *** [build-nano/sensors_passive.ino.o] Error 1
Seems like the BOARD_TAG is still incorrect or I'm missing another var in the makefile. Any thoughts?
Now there has been another change since that was written. atmega328 can only be used with official Arduino boards made in the last couple of months. If you're using an old official Nanos or Nano clone you need to use atmega328old instead of atmega328.
Ah yes, I suppose I should have started with that. Although, when I started this topic, I didn't really know what a makefile/make script was. This was a crash course in learning Arduino on command line.
I will try your solution and let you know. This is the post I was working on:
Using another RPi that I have with me that's all update but has VNC server and GUI, I am able to compile the sketch using IDE 1.8.5. I think I haven't properly pointed to the installation directory in the makefile. And I don't think Arduino-Makefile will work to build it because it's not updated for 1.8.6 (from what I've read).
If I still can't get it working tomorrow in command line, I will reinstall the Raspbian Full on the RPi Zero so I can use the IDE instead of doing it through command line. It seems like the resources and support for using command line to compile Arduino sketches is lacking somewhat.
If you want, you can just use Arduino IDE directly from the command line, rather than using the GUI. I use the Arduino IDE CLI extensively for continuous integration on headless Linux systems (Travis CI and Circle CI). It works great. I've also used it without any problems via SSH on a headless Raspberry Pi. You can see the reference here:
Looking at this from a different angle, from the original post, why not have a software serial type connection to the pi, leaving the USB connector free for updating the NANO sketch whoever you want ??
I know this a bit late in this thread, but fwiw I wrote a little wrapper, ardi, around arduino-cli that lets you compile, upload, and read logs from the serial port from command line with a bit more ease. It attempts to automatically detect your board and has an option to watch a sketch file and auto re-compile / re-upload on save. Feel free to use it if you find it helpful in anyway