Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Project transfer from PICAXE

  1. #1
    Junior Member
    Join Date
    Dec 2019

    Project transfer from PICAXE

    I have spent most of my time with micro controllers with picaxe, they are easy to learn, simple to use and can bring more than enough processing power for most things. However I have been thinking about updating some of my projects with more abilities and faster throughput. I have dabbled with Arduino a little - not enough to be that good with coding them. With that in mid I decided to have a look around at what else was out there.

    One of the primary thing I wanted to do was speed up one project in particular, so naturally obtaining the fastest unit I could would be a good starting point. I arrived at the teensy 4, which not only offered the speed I was looking for, but also offers routes for upgrading in the future once the basics of the project are laid down.

    The basics:
    this is what I produced with PICAXE:
    I have done some development to move the project along, but haven't actually gotten a full circuit design as I wasn't sure which direction I was going to go.
    The original project required any sensors to be plugged into the main unit, this had the bonus of flexibility, at the cost of ease of use. this is also true with the auxiliary light that the unit can control.
    Timing can also be inaccurate on the picaxe simply due to the tokenized interpreted coded system that it uses.

    Further development:
    I have done some further development, made use of a nextion display which helped to free up some code space.
    I made use of the schematic diagram of this:
    once that was made up I returned to using a comparator interrupt to trigger a response. The input from the mic/amp circuit is compared to the internal resistor ladder allowing the user to select the threshold of the input. This was done to allow other analogue sensors to be connected with as little additional circuitry as possible. The X2 series of PICAXE microcontrollers have 2 comparators to boot, so 2 sensors can be used at time. The plan was to have a light sensor on one, and the sound sensor on the other and the user can select either or both and the trigger level for them - imagine photographing a lighting/thunder storm.
    Further to that, being able to have one start a timer, and the other stop a timer, calculate a speed and ask if it was faster/slower than the required amount before snapping a shot.
    I also adding the ability for it to control time lapse.

    Hopefully that covered everything I have so far in regard to the project to date.

    I have already purchased a teensy 4.0 but have not done anything with it. I am still looking through all the documentation.
    Although I still have a lot of research to do, I have noticed that it has the ability to deal with audio. I am assuming, that by comparison to, something similar to the spark fun unit and an interrupt, direct audio processing will be slow. This I think would be more prevalent as I don't actually need to do any frequency processing or filtering, just detect when the sound reaches or drops to a certain level.
    From what I have seen so far there is a comparator to use - that all I know far.
    However at his point I don't know if its worth while using an ISR or just continuously poll the ADC compare it a variable that can be set by a user interface of some description.

    And finally, what are recommendations for writing code. As I said before, I don't have a massive amount of Arduino coding experience so I don't know if its going to be better to start a fresh with something closer to C than Arduino C.

    Thanks for any thoughts on this, and I am happy to clarify anything and answer any questions/go over thing that I have likely missed.

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Quote Originally Posted by orac View Post
    And finally, what are recommendations for writing code. As I said before, I don't have a massive amount of Arduino coding experience so I don't know if its going to be better to start a fresh with something closer to C than Arduino C.
    Interesting looking project.

    One note - Arduino C is just C or c++. Standard C calling and libraries and function. The only unique part AFAIK is pre-processing in the SKETCH file xxx.INO. Where some C requirements are resolved for the user - like prototyping before use and gathering information about things used without being explicit to the rules of normal C at all times that would fail a normal build.

    But writing normal C or c++ as used by the GCC compiler is acceptable and the sketch file can be empty and having other source files in that sketch directory inspires a dynamic 'MAKEfile' to be created to make a usable binary as long as the Compiler and Linker are given the needed/normal info about usable code etc. Where needed info isn't given to complete that building - normal warnings and errors during the build are presented in Verbose mode.

    So given C/cpp knowledge it works with the IDE in a sketch. Depending on OS in use and desired build method there are ways to stay out of the IDE and get code running on the Teensy presented in the forum.

    Some may be windows specific like or In windows editor of choice like that I use extended with batch files in TSET that inspire the Arduino IDE to run from command line. There are OS generic things that others seem to use like PlatformIO ...

  3. #3
    In terms of the language, Arduino is C++, and you can use both c and C++. Most libraries are c++, but if dig around enough you occasionally come across a bit of c. See? (I'm not sorry for that at all)
    Arduino is designed for new programmers and does a lot to crush the learning curve by basically hiding loads from the user. Experienced programmers often get very confused when moving to Arduino, because the compilation process does a bunch of stuff that the user doesn't get told about. I'll throw a few out that I know of

    The .ino sketch contains a setup and loop function. Arduino re-formats this into something like
    #include <Arduino.h>
    #include stuff
    // some other preprocessor defines perahps?
    int main()
      int globalVariblesDefined; // I think here?
    it basically handles everything needed to turn the sketch into something that can actually be compiled - like wherever all those Arduino built-in function and objects come from.

    Arduino does everything in a temporary folder. It hoovers everything up in your sketch folder, but not subfolders (exception later), moves it somewhere, and compiles the lot. This ruins any relative file paths you may want to use because /librarySubfolder/Library.h doesn't exist anymore.

    If a subfolder /src is present, this folder also get it's contents used for compilation, and relative paths to it still work. Though I've not had success with "src/header.h"

    It also compiles everything in the sketch folder, regardless of whether it is included in your .ino file, if it's .ino, or .cpp.

    Arduino concatenates every .ino file in the folder, starting with the file matching the folder name, then in ascending ASCII order. (where 9.ino, ?.ino, A.ino, and a.ino would be in that order)

    For it's .ino files, Arduino generates function prototypes/forward declarations as needed.

    Arduino's IDE highlights every single possible keyword that it knows of. Not just language keywords like "extern", but for every class that has a list of keywords.txt for its functions and members, regardless of wether that library is included. This results in random text turning on. ( Pretend like the word "on" is orange for no reason and you get the idea). It has no effect, but it's a smidge confusing the first time. It's supposed to help, because if you've correctly typed myClass.myFunction() myFuncation should go orange. Ironically this will happen even if the library hasn't been included

    A few of Arduino's built in-functions are actually macros (#define) in disguise. abs(x) is well known to actually expand to a macro, but it's all lower case and highlighted orange like a function. Why this isn't ABS_VAL(x) is beyond me
    Arduino wants you to write your own libraries and store them in the libraries subfolder, wherever your install is. Any library here can be included using #include <libraryFile.H> and it works fine. The thought of storing my work across two separate drives becuase Arduino won't let me use a normal #include does make me a lil queasy. Also version control becomes a bit of a problem.

    You can #include "Absolute/File/Path.h", but Arduino doesn't follow that to the .cpp file and compile that as well. I think this is becuase the file is included, before the main.cpp file is passed to the compiler, so the compiler doesn't see the file path but the contents of the file. If you're desperate, you can also #include at the end of your sketch an absolute filepath to the .cpp file. I've done this and I'm still sad about it.


    I moved to visual studio a few years back and have 0 regrets. Visual micro, the addon to use it for compiling arduino handles all the faff for you. As long as you use the class wizard to generate your header and source they end up playing ball nicely. You can also do your version control within VS as a bonus. You still get some of the quirks like the abs() being a macro, but alot of them dissaper.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts