3

Recently I have started developing for Arduino Uno. I have 10 years experience in software development (C#, Delphi), but not much with C/C++. Compiling the Arduino sketches seems a little slow, and debugging isn't as convenient as it could be on a PC (compile, upload, watch the serial monitor, modify code, start over.... way too slow with lots of unnecessary steps) So what I would like to achieve is to organize my code in a way to be able to compile my code either to Arduino, or to PC for debugging purposes (to a small console app). I know that there are libraries that cannot be used on a PC, but those can be abstracted away (hidden behind a facade or something like that). Unfortunately I could not find any tutorials, or articles how to do this. So I hope you can help me out.

BTW I'm using Visual Studio (with Visual Micro) on a Windows 10 computer.

morcibacsi
  • 33
  • 2

1 Answers1

2

I haven't done it yet, but you could do the following things to get a somewhat close approximation:

  • Make three different projects, one for the PC (only), e.g. Visual Studio, and one for Arduino (with the default Arduino IDE or e.g. Visual Micro). The last will be a generic library to be used for both the PC and Arduino.
  • Use the Arduino specific libraries only for the Arduino project.
  • Create facade/wrapper classes for each Arduino library.
  • Use a mock/stub for the Arduino libraries in the PC only project.
  • Put all non-hardware related code in separate classes, to be used by both projects.
  • Write unit tests for the PC only project.
  • The PC project will be tested by unit tests, and can be debugged on a PC
  • Only the specific Arduino libraries/interfaces have to be tested using the 'hard way', e.g. with Serial.

So the projects (including testing) will look like:

  • PC Project
    • References common code
    • Stubs for Arduino libraries, stubs can possibly be reused by PC Unit tests
  • PC Unit Tests
    • Unit tests
    • References common code
  • Arduino Project
    • Containing Arduino libraries
    • References common code
  • Common Code
    • All domain specific classes
Michel Keijzers
  • 13,014
  • 7
  • 41
  • 58