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

Thread: Arduino uno to Teensy help needed

  1. #1
    Junior Member
    Join Date
    Aug 2017
    Posts
    13

    Arduino uno to Teensy help needed

    Hi guys,

    I am doing a light painting led strip application. Uses a SD card to store a BMP image, and print the image strip by strip over an array of LEDs.

    my project uses a Bluno Nano(same mcu as Uno, but with integrated BLE).


    my adafruit neopixel library wont work properly after dynamic memory goes above 70%. 69% will still work.. probably due to lack of RAM



    was introduced to Teensy 3.1/3.2. hoping to verify its workability first before purchasing.

    followed the tutorial on how to use teensy, installed the installer, installed the teensy libraries, set my board to 'Teensy 3.1/3.2', the rest like serial,etc are default.
    if needed, my code is here: https://github.com/tzijie/LightStick...oPixel_Painter

    Tried to verify my code, and receive the following errors. could someone assist me and point me in the right direction? thank you!
    Code:
    Arduino: 1.8.3 (Windows 10), TD: 1.38, Board: "Teensy 3.2 / 3.1, Serial, 96 MHz (overclock), Faster, US English"
    
    In file included from C:\Users\tzj\Desktop\LightStick_Arduino\NeoPixel_Painter\NeoPixel_Painter.ino:14:0:
    
    gamma.h:19: error: 'const uint8_t gamma []' redeclared as different kind of symbol
       gamma[] = { // Brightness ramp for LEDs
    
             ^
    
    In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WProgram.h:36:0,
    
                     from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/Arduino.h:3,
    
                     from C:\Users\tzj\AppData\Local\Temp\arduino_build_388109\sketch\NeoPixel_Painter.ino.cpp:1:
    
    c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\math.h:350:15: note: previous declaration 'double gamma(double)'
    
     extern double gamma _PARAMS((double));
    
                   ^
    
    NeoPixel_Painter: In function 'void convertIMG()':
    NeoPixel_Painter:170: warning: suggest parentheses around assignment used as truth value 
           if(found = bmpProcess(infile, NULL, &b)) {
    
                                                  ^
    
    NeoPixel_Painter:225: error: 'TCCR1A' was not declared in this scope
       TCCR1A = _BV(WGM11) | _BV(WGM10);
    
       ^
    
    In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/wiring.h:38:0,
    
                     from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WProgram.h:45,
    
                     from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/Arduino.h:3,
    
                     from C:\Users\tzj\AppData\Local\Temp\arduino_build_388109\sketch\NeoPixel_Painter.ino.cpp:1:
    
    NeoPixel_Painter:225: error: 'WGM11' was not declared in this scope
       TCCR1A = _BV(WGM11) | _BV(WGM10);
    
                    ^
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/core_pins.h:47:22: note: in definition of macro '_BV'
    
     #define _BV(n)  (1<<(n))
    
                          ^
    
    NeoPixel_Painter:225: error: 'WGM10' was not declared in this scope
       TCCR1A = _BV(WGM11) | _BV(WGM10);
    
                                 ^
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/core_pins.h:47:22: note: in definition of macro '_BV'
    
     #define _BV(n)  (1<<(n))
    
                          ^
    
    NeoPixel_Painter:226: error: 'TCCR1B' was not declared in this scope
       TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS11) | _BV(CS10);
    
       ^
    
    In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/wiring.h:38:0,
    
                     from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WProgram.h:45,
    
                     from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/Arduino.h:3,
    
                     from C:\Users\tzj\AppData\Local\Temp\arduino_build_388109\sketch\NeoPixel_Painter.ino.cpp:1:
    
    NeoPixel_Painter:226: error: 'WGM13' was not declared in this scope
       TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS11) | _BV(CS10);
    
                    ^
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/core_pins.h:47:22: note: in definition of macro '_BV'
    
     #define _BV(n)  (1<<(n))
    
                          ^
    
    NeoPixel_Painter:226: error: 'WGM12' was not declared in this scope
       TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS11) | _BV(CS10);
    
                                 ^
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/core_pins.h:47:22: note: in definition of macro '_BV'
    
     #define _BV(n)  (1<<(n))
    
                          ^
    
    NeoPixel_Painter:226: error: 'CS11' was not declared in this scope
       TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS11) | _BV(CS10);
    
                                              ^
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/core_pins.h:47:22: note: in definition of macro '_BV'
    
     #define _BV(n)  (1<<(n))
    
                          ^
    
    NeoPixel_Painter:226: error: 'CS10' was not declared in this scope
       TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS11) | _BV(CS10);
    
                                                          ^
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/core_pins.h:47:22: note: in definition of macro '_BV'
    
     #define _BV(n)  (1<<(n))
    
                          ^
    
    NeoPixel_Painter: In function 'void loop()':
    NeoPixel_Painter:322: error: 'TIMSK0' was not declared in this scope
       TIMSK0 = 0; //for smoother playback
    
       ^
    
    NeoPixel_Painter:354: error: 'OCR1A' was not declared in this scope
       OCR1A = (F_CPU / 64) / linesPerSec;          // Timer1 interval
    
       ^
    
    NeoPixel_Painter:360: error: 'TIFR1' was not declared in this scope
         while(!(TIFR1 & _BV(TOV1)));               // Wait for Timer1 overflow
    
                 ^
    
    In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/wiring.h:38:0,
    
                     from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WProgram.h:45,
    
                     from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/Arduino.h:3,
    
                     from C:\Users\tzj\AppData\Local\Temp\arduino_build_388109\sketch\NeoPixel_Painter.ino.cpp:1:
    
    NeoPixel_Painter:360: error: 'TOV1' was not declared in this scope
         while(!(TIFR1 & _BV(TOV1)));               // Wait for Timer1 overflow
    
                             ^
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/core_pins.h:47:22: note: in definition of macro '_BV'
    
     #define _BV(n)  (1<<(n))
    
                          ^
    
    NeoPixel_Painter:361: error: 'TIFR1' was not declared in this scope
         TIFR1 |= _BV(TOV1);                        // Clear overflow bit
    
         ^
    
    In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/wiring.h:38:0,
    
                     from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WProgram.h:45,
    
                     from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/Arduino.h:3,
    
                     from C:\Users\tzj\AppData\Local\Temp\arduino_build_388109\sketch\NeoPixel_Painter.ino.cpp:1:
    
    NeoPixel_Painter:361: error: 'TOV1' was not declared in this scope
         TIFR1 |= _BV(TOV1);                        // Clear overflow bit
    
                      ^
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/core_pins.h:47:22: note: in definition of macro '_BV'
    
     #define _BV(n)  (1<<(n))
    
                          ^
    
    NeoPixel_Painter:381: error: 'TIMSK0' was not declared in this scope
      TIMSK0 = 1;
    
      ^
    
    NeoPixel_Painter: In function 'boolean bmpProcess(char*, char*, uint8_t*)':
    NeoPixel_Painter:450: warning: dereferencing type-punned pointer will break strict-aliasing rules 
         (*(uint16_t *)&sdBuf[ 0] == 0x4D42) &&    // BMP signature
    
                                ^
    
    NeoPixel_Painter:451: warning: dereferencing type-punned pointer will break strict-aliasing rules 
         (*(uint16_t *)&sdBuf[26] == 1)      &&    // Planes: must be 1
    
                                ^
    
    NeoPixel_Painter:452: warning: dereferencing type-punned pointer will break strict-aliasing rules 
         (*(uint16_t *)&sdBuf[28] == 24)     &&    // Bits per pixel: must be 24
    
                                ^
    
    NeoPixel_Painter:453: warning: dereferencing type-punned pointer will break strict-aliasing rules 
         (*(uint32_t *)&sdBuf[30] == 0)) {         // Compression: must be 0 (none)
    
                                ^
    
    NeoPixel_Painter:455: warning: dereferencing type-punned pointer will break strict-aliasing rules 
         bmpImageoffset = *(uint32_t *)&sdBuf[10]; // Start of image data
    
                                                ^
    
    NeoPixel_Painter:456: warning: dereferencing type-punned pointer will break strict-aliasing rules 
         bmpWidth       = *(uint32_t *)&sdBuf[18]; // Image dimensions
    
                                                ^
    
    NeoPixel_Painter:457: warning: dereferencing type-punned pointer will break strict-aliasing rules 
         bmpHeight      = *(uint32_t *)&sdBuf[22];
    
                                                ^
    
    In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WProgram.h:41:0,
    
                     from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/Arduino.h:3,
    
                     from C:\Users\tzj\AppData\Local\Temp\arduino_build_388109\sketch\NeoPixel_Painter.ino.cpp:1:
    
    NeoPixel_Painter:539: warning: pointer to a function used in arithmetic 
                 corr = pgm_read_byte(&gamma[raw]);          // Gamma-corrected
    
                                                ^
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/avr/pgmspace.h:95:55: note: in definition of macro 'pgm_read_byte'
    
     #define pgm_read_byte(addr) (*(const unsigned char *)(addr))
    
                                                           ^
    
    'const uint8_t gamma []' redeclared as different kind of symbol
    
    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.
    p.s. ive deleted/moved my original arduino Adafruit_NeoPixel library to let the ide use teensy's neopixel library.

  2. #2
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,915
    Your code is using direct calls to a number of 8 bit AVR functions, like setting the timer, and suspect avr/pgmspace is not going to work out of the box either. Unfortunatly because so much of what you have ties directly to the AVR in pursuit of performance a straight port isn't really going to work.

    What you want to do is certainly possible but you will need to decide if you are up for rebuilding a fair bit of code. Best method is probably to start with a neopixel+SD card shell that uses the optmisied Teensy version of code and then move your special functions across to convert the SD image and process it's pixels out. That breaks things down into smaller chunks.

    Be aware 3.3V micros can't directly control 5V LED strips so if going this route you'll need to work out a step up process (see https://www.pjrc.com/store/prop_shield.html or the OctoWS shield+library).

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,338
    You can probably replace that timer stuff with elapsedMicros or IntervalTimer. Or you could redesign it to directly access the hardware Timers in Teensy 3.2 as it does for the AVR timers, but that's a much steeper learning curve.

    The chunk of assembly language near the end could be removed and you can just use the normal Adafruit NeoPixel show function, since there's plenty of memory on Teensy 3.2. Or if you *really* want to keep it designed this way, you could find the Teensy-specific code in that library and copy it, as was done for AVR.

    While not a problem on Teensy 3.2, you should also be aware this code makes unaligned 32 bit memory access. On AVR, the compiler just reads the memory 4 times. On ARM, a single instruction will read all 32 bits. On Teensy 3.x, the Cortex-M4 hardware is able to automatically detect the 32 bit access isn't aligned to the 32 bit memory. It does 2 accesses for you and gives you the proper result. But not all ARM chips have this. Unaligned access will crash on Teensy LC, Arduino Zero and other Cortex-M0 boards.

    The freeRam function might also not work, but it doesn't seem to be doing anything important. There's so much RAM on Teensy 3.2 that you shouldn't need to bother.

  4. #4
    Junior Member
    Join Date
    Aug 2017
    Posts
    13
    Quote Originally Posted by GremlinWrangler View Post
    Your code is using direct calls to a number of 8 bit AVR functions, like setting the timer, and suspect avr/pgmspace is not going to work out of the box either. Unfortunatly because so much of what you have ties directly to the AVR in pursuit of performance a straight port isn't really going to work.

    What you want to do is certainly possible but you will need to decide if you are up for rebuilding a fair bit of code. Best method is probably to start with a neopixel+SD card shell that uses the optmisied Teensy version of code and then move your special functions across to convert the SD image and process it's pixels out. That breaks things down into smaller chunks.

    Be aware 3.3V micros can't directly control 5V LED strips so if going this route you'll need to work out a step up process (see https://www.pjrc.com/store/prop_shield.html or the OctoWS shield+library).
    Quote Originally Posted by PaulStoffregen View Post
    You can probably replace that timer stuff with elapsedMicros or IntervalTimer. Or you could redesign it to directly access the hardware Timers in Teensy 3.2 as it does for the AVR timers, but that's a much steeper learning curve.

    The chunk of assembly language near the end could be removed and you can just use the normal Adafruit NeoPixel show function, since there's plenty of memory on Teensy 3.2. Or if you *really* want to keep it designed this way, you could find the Teensy-specific code in that library and copy it, as was done for AVR.

    While not a problem on Teensy 3.2, you should also be aware this code makes unaligned 32 bit memory access. On AVR, the compiler just reads the memory 4 times. On ARM, a single instruction will read all 32 bits. On Teensy 3.x, the Cortex-M4 hardware is able to automatically detect the 32 bit access isn't aligned to the 32 bit memory. It does 2 accesses for you and gives you the proper result. But not all ARM chips have this. Unaligned access will crash on Teensy LC, Arduino Zero and other Cortex-M0 boards.

    The freeRam function might also not work, but it doesn't seem to be doing anything important. There's so much RAM on Teensy 3.2 that you shouldn't need to bother.
    thanks guys!.. guess the teensy 3.0 and above with ARM chip isnt gonna work for me. my priority now isnt to convert the code, but rather, the smartphone application associated to it..

    in that case i should use teensy++ 2.0 which uses an AVR chip.. prolly gonna need a sd and bluetooth breakout then..

    for bluetooth module, my previous bluno nano, once connected to bluetooth, establishes connect to the serial, allowing me to use the serial monitor(the phone app version) to send and receive serial messages.
    for this case, will any bluetooth module work? or do i specifically need to get serial protocol ones?

  5. #5
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,915
    With the phone ap end, would suggest sticking with explicitly serial modules. Other may have settings buried that allow you to send AT commands or similar to change them, but many will be stripped down to just what that OEM needed the modules to do and few mass market bluetooth devices need a serial interface.

    Re Teensy2++, does your code compile for that? It'll be a closer fit for the Uno code but will most likely still have registers that differ.

  6. #6
    Junior Member
    Join Date
    Aug 2017
    Posts
    13
    Quote Originally Posted by GremlinWrangler View Post
    With the phone ap end, would suggest sticking with explicitly serial modules. Other may have settings buried that allow you to send AT commands or similar to change them, but many will be stripped down to just what that OEM needed the modules to do and few mass market bluetooth devices need a serial interface.

    Re Teensy2++, does your code compile for that? It'll be a closer fit for the Uno code but will most likely still have registers that differ.
    what do you mean by explicitly serial modules?

    Yeah, i changed the board to teensy2++ and i am able to compile my code. both uno and teensy2++ uses AVR 8bit chips too.


    my current bluno has an on-board bluetooth, that when connected to the bluetooth on the phone app, will listen on the serial port for incomeing Serial.print() s on the board.

    the phone app uses serialSend("stuff to send"); to send characters to the board to tell it to do stuff.

    does all bluetooth modules work the same? any idea on the type of bluetooth module i should be getting?

  7. #7
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,915
    Blue tooth is like USB, it's just a method for shifting data so you need to make sure your module is going to handle serial, not audio, ethernet, mouse or whatever else people have worked out how to move via bluetooth.

    So yes you want to be searching for bluetooth serial or bluetooth UART. And be careful that you don't end up with one that only 'serials' to a custom phone ap.

  8. #8
    Junior Member
    Join Date
    Aug 2017
    Posts
    13
    Quote Originally Posted by GremlinWrangler View Post
    Blue tooth is like USB, it's just a method for shifting data so you need to make sure your module is going to handle serial, not audio, ethernet, mouse or whatever else people have worked out how to move via bluetooth.

    So yes you want to be searching for bluetooth serial or bluetooth UART. And be careful that you don't end up with one that only 'serials' to a custom phone ap.
    Hi, im sorry but what do you mean by "don't end up with one that only 'serials' to a custom phone app"?

  9. #9
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,915
    Before buying anything, check what software they point you to, and see if your current Uno can talk to it (hopefully the one you already use with the one bluno Nano). If it can't, or needs a custom driver or library or some other magic to do anything other than run a demo ap then the hardware on sale probably isn't a generic UART.

    You will also need to check if the module is 5V compatible if used with a Teensy2++

    Edit, quick check of the usual places suggests I'm out of date on Arduino bluetooth modules and most serial modules really are generic UARTs, not the 'pairs to custom ap' that I'd run into previously. Though didn't see any that were 5V compatible so some interesting design decisions there.
    Last edited by GremlinWrangler; 09-04-2017 at 10:40 AM.

Posting Permissions

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