Which program am I running?

Do you ever get in a muddle as to which program is loaded in your Arduino?

It would be good if the IDE could read some identification from the loaded program.

Meanwhile I am using code like this to output to the Serial Monitor

  • it seems to work when ANY program with serial output is loaded in the IDE
  • so long as you set the COM port.

void setup() {
Serial.begin(9600);
Serial.println("\n*** Source File: Data_logger_button_v1.ino ***\n");
}

I realise this is pretty simplistic. Maybe someone has a better idea?

I have solved that problem in much the same way. I use this Python program to call the Arduino IDE to compile and upload the program. It figures out the full path name to the .ino file and includes that in the .ino file before it calls the compiler. This is the sort of thing that is in my files

Serial.println(F("Source File /mnt/sdb1/SGT-Docs/ModelRailways/RadioControl/Dubl00BPRC/ComputerControl/ArduinoCode/LocoMaster.ino"));

I use Geany to edit my program code and the Python program can be called directly from it.

...R

Thanks for that Robin2

Your use of 'Source File' is much better terminology!

  • have changed my post to use it
void setup() 
{

  Serial.begin(9600);
  Serial.println(__FILE__);
  // other code

} // setup

The preprocessor will replace 'FILE' with your *.ino file name.

tf68:
<…>
The preprocessor will replace ‘FILE’ with your *.ino file name.

I work at any time with bare, UNO, Mega, mini, micro, nano, STM32F103, ESP8266 …

So, while the FILE pre-processor trick is most interesting, I also try and organize my source files into a sensible directory. Examples:

/arduino/sources
             |
            Nano/2x16_LCD
                /ILI9341
                /128x64_OLED
                /BMP180

It helps when I get ready to look for a template for the next project.

The other thing I do is embed all 3rd party libs within the sketch folder. As I post projects on my project page, it is so simple to have one ZIP. Hard disk space is cheap and all I ever have to do is install an old IDE version and download the Zip to answer a question on a project years old.

Ray

Thank you tf68

  • Crafty!
  • I was hoping someone would come up with something like that
  • and as with mine it works when ANY program with serial output is loaded in the IDE

The only problem is it outputs the entire address of the file
i.e… C:\Documents and Settings\David\My Documents\Arduino- - My Arduino sketches\DataLogger\Data_logger_button-v2\Data_logger_button-v2.ino
Is there any way of reducing the output to just the file name?

mrburnette
Although I agree with the need to structure the storage of information and code I am afraid I don’t see what you are trying to say. My problem is that I am developing so many programs on so many Arduinos that I sometimes forget which one is loaded where! tf68’s crafty answer is just what I needed.

My problem is that I am developing so many programs on so many Arduinos that I sometimes forget which one is loaded where!

A problem that I am sure many of our forum readers wish they had :slight_smile:

I don't see what you are trying to say.

I was only attempting to add some possible options to any reader looking to organize multiple projects... by board and by display or other sensor element(s).

For readers that may be publishers, too, I made the point of embedded libraries into the sketch folder. Maybe only 1% of readers will resonate with that idea, but over time I have had numerous PMs from folk thanking me for that bit of wisdom. But like wasabi sauce, not everyone will like that idea.

I regret you got no value from my post, but that's OK.

Ray

mrburnette

It looks like you were editing your last post as I was preparing the reply to your previous one!

Thanks for the link to your website - I can see where I will be going when I get on to ESP 8266 and OLED - that's the trouble with Arduino - as fast as I master one thing I get involved in something else. There is a steep learning curve out there!

Sorry you felt that I 'got no value' from your post - I just didn't know where you were coming from - but now I understand - in a rapidly changing world you do need to keep things all together. If only Microsoft had stuck to that I would still be able to run my favourite old software and hardware!

mrburnette:
The other thing I do is embed all 3rd party libs within the sketch folder. ... Hard disk space is cheap

+1

It also means that your project will work even if a new version of the library emerges elsewhere.

The approach I have devised also deals with two Arduino "features" that I find a real PITA - the need to have a folder named myProject for the file myProject.ino and the inability to refer to INCLUDE files by relative path names - for example so you can include the same file in both the Master and Slave programs.

...R

The standard predefined macros are specified by the relevant language standards, so they are available with all compilers that implement those standards.

FILE
This macro expands to the name of the current input file, in the form of a C string constant. This is the path by which the preprocessor opened the file, not the short name specified in ‘#include’ or as the input file name argument. For example, "/usr/local/include/myheader.h" is a possible expansion of this macro.

The result you get back is probably dependent on how the Arduino build system organizes things. On my system I get only the file name returned.

While nobody would call me well organized I don't have any problems tracking down my source files once I have the name.

tf68

Thanks for that. It would be interesting to find what range of file paths people get. Both my Win XP and Win 7 give the full file path.

Just to show how grey my beard really is, all my real time programming was in CORAL 66 and I was on the BSI committee which standardised it (BS 5905:1980). Since then I have used Pascal and Delphi, but only a tiny bit of C.

The problem I have with Arduino is not knowing which bits are C, C++ and just straight Arduino - and that is before you have to work around the bugs. For example it took me ages to work out samples of code which used streaming - a bit of commenting would have helped, but to the uninitiated it had me really confused - it was the << bits that really bugged me! But now I find it SO useful.

However - Google to the rescue…

has the solution…

#include <string.h>

#define FILENAME (strrchr(FILE, ‘/’) ? strrchr(FILE, ‘/’) + 1 : FILE)

For Windows use ‘\’ instead of ‘/’.

  • and that works a treat!
  • just the filename comes out now

freddie43:
Thanks for the link to your website - I can see where I will be going when I get on to ESP 8266 and OLED - that’s the trouble with Arduino - as fast as I master one thing I get involved in something else. There is a steep learning curve out there!
<…>
Just to show how grey my beard really is, all my real time programming was in CORAL 66 and I was on the BSI committee which standardised it (BS 5905:1980). Since then I have used Pascal and Delphi, but only a tiny bit of C.

I strongly recommend the NodeMCU board programmed under ArduinoIDE using igrr’s core files installed by Board Manager from the JSON link.

The NodeMCU is going to run about $4 from AliExpress, but it has the USB-serial chip onboard. When the ESP8266 is programmed under Arduino, whatever firmware (Lua, AT, etc.) is overwritten by your compiled sketch plus the ESP proprietary library that supports the chip networking, etc. Said another way, the proprietary code runs in one time slice and the Arduino code runs in a separate time slice. The Arduino code must loop() every 50mS or less but if you have routines that take longer, you are responsible for using delay(0) or yield() to let the RF section of the chip have cpu time. It’s a weebit tricky, but you will get the hang in no time. (If not, the WDT will reboot to let you know you need to work on your Arduino sketch code :o )

The ESP8266 is so inexpensive, buy a few rather than just 1 or 2. You do not need to have a WiFi project to use the ESP8266 as a fast Arduino with lots of SRAM and flash. That is, you can disable the RF section power (but not the timeslice) and the ESP8266 will run as a fast Arduino, up to 160MHz.

Most NodeMCU boards are 4M flash modules which means you can configure 3M of the flash for a small file system using SPIFFS. This is a great place for storing lots and lots of strings, user instructions, page formatting, or formatted output.

OLEDs…
Be careful when you order, while the controller chip on the board may support both I2C and SPI, the physical pinout generally will only support one or the other. If 4-pins, it is I2C.

The price of the little OLEDs went up to about 2x or 3x the price in Spring of this year and stayed high most of the summer. Prices are now down to under $3 USD.

General note on purchasing from China. Beware Chinese New Year: January 28, 2017. The entire country shuts down for the occasion. Order taking, shipping, email notifications, etc. are all down a minimum of a week, but the ripple effect is more like 3 weeks. If you need a winter project, back-up the 6 week to 8 week (or longer) interval and order as early as possible… Now is a good time!

I programmed in COBOL a bit in the Burroughs’ days of 1973-1976. I also did some low-level MTR code on the L8000 series. Do yourself a favor, print this page from the Arduino Reference. When you are programming, the commands on this single page are Arduino abstractions. If you need to go to full C++ to accomplish what you need to do … go for it… but look up the syntax on the web first just to be certain you get the calling parameters and the variable types correct.

Oh, one big stinking thing:
When coding an 8-bit Arduino, INT is 16-bit
When coding a 32-bit Arduino, INT is 32-bit

Age has no bearing on how much fun you can have with this hobby. Do not get too serious. The young kids on the forum have come up through HTML and Java and are going to have a completely different way of looking at a problem. We older coders may have an advantage because we look at a problem as small steps because old machines had limited resources. Define your project and your budget (important.) Identify your hardware sources. Identify your software resources. Research libraries required and alternate libraries (in the event of conflict - it happens!) Always start a project by running the Arduino through a test suite … poor soldering often manifests itself in an open or shorted I/O. DO NOT assemble the entire project at one time!
Assemble the Arduino and the display and test.
Add sensors and test.
Add relays/servos/steppers and test.
Pull the project together as a system.

Because libraries often use interrupts, libraries can interact negatively. Some libraries poll while some libraries block which means that no matter how you code your loop, a call to a library that blocks can be a disaster. I always look over a potential library to determine if i understand what is really going on under the hood.

… and have fun.

Ray

Thanks Ray. All useful info - especially on bulk buying. I have just bought a bundle of miniature micro screw stepper motors for my grandson’s train set for little more than the price of one. The lad is only 9 but he is utterly fascinated by the Arduino. We are definitely having FUN!

Yes, I have the Arduino Language Reference page, but there was nothing there to help me understand lines like:

cout << F("Serial number: ") << hex << cid.psn << dec << endl; in ‘SD_info.ino’

The knowledge that ‘<<’ was ‘bitshift left’ didn’t help much. But thanks to Google I eventually stumbled on streaming.

BTW CORAL 66 had nothing much to do with COBOL other than the influence of Algol. It was a compact real time programming language that enabled us to monitor and control the distribution of electricity and other public utilities in large networks from remote control desks on computers with only 192Kbytes RAM and 4Megs of disk (yes - that was in the late 1970’s!!). And they ran for 15 years before replacement.

mrburnette:
Said another way, the proprietary code runs in one time slice and the Arduino code runs in a separate time slice.

I was reading a little about the ESP8266 in the last few days and it occurred to me that it must do something like that.

The picture in my mind is that there are two CPUs - {W} running the WiFi and {A} running the Arduino code - such as the "Blink" program and {A} can communicate with {W} as needed. A bit like the Arduino and the Linux sides of a Yun.

Do you have a link where that is explained more clearly / more extensively. I did not see anything when I was searching myself.

...R

Would this be a good point at which to start a new thread about ESP and NodeMCU?

I will want to come back here eventually but I will never remember that all the very helpful posts from Ray are hidden away in this thread!

Robin2:
I was reading a little about the ESP8266 in the last few days and it occurred to me that it must do something like that.

The picture in my mind is that there are two CPUs - {W} running the WiFi and {A} running the Arduino code - such as the "Blink" program and {A} can communicate with {W} as needed. A bit like the Arduino and the Linux sides of a Yun.

Do you have a link where that is explained more clearly / more extensively. I did not see anything when I was searching myself.

...R

The Official word on the Arduino timeslice is here. That recommends 20mS but the RF section seems to function OK even if 50mS is consumed ... like any specification, things can be stretched a weebit.

The Reference section is going to look very familiar with little deviation from Arduino except board stuff.

About the ESP native time-slice and the Arduino area time-slice...
The ESP8266 SDK ships (today) with a working RTOS implemented but back a couple of years ago, the SDK was incomplete.
While the Arduino code was being developed, a task switcher known as NonOS was utilized. NonOS has a low memory footprint, is efficient, but does not provide scheduling, pre-emptive multitasking, or other capabilities of a true RTOS.

The 32-bit RISC core of the ESP8266 is not terribly powerful in terms of today 32-bit offerings. Because the instruction flash is off-chip, there is an instruction cache SRAM implemented which eliminates delays going back & forth to the external flash. The STM32F103 in my testing is superior because of advanced system-level design such as DMA. But, the ESP8266 at $4 is in the same price range as the STM32F103 boards such as the Maple Mini clone and there is more flash and more SRAM on the ESP8266 plus the RF WiFi radio.

Perhaps if the Arduino core were written today, a true RTOS would have been utilized. But, with the programmer following a few basic rules, good C++ performance can be had on the Arduino side and still have the RF side perform. For folks that do not want the RF section at all, it can be turned-off and the ESP8266 can just be a ESP'mini.

Ray

Thanks Ray. I have bookmarked your Reply for study later.

...R