element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Light Up Your Life
  • Challenges & Projects
  • Design Challenges
  • Light Up Your Life
  • More
  • Cancel
Light Up Your Life
Forum general question - working with the zero and Würth's github examples
  • News
  • Forum
  • Projects
  • DC
  • Leaderboard
  • Files
  • Members
  • More
  • Cancel
  • New
Join Light Up Your Life to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 4 replies
  • Subscribers 42 subscribers
  • Views 126 views
  • Users 0 members are here
Related

general question - working with the zero and Würth's github examples

Anthocyanina
Anthocyanina 6 days ago

has anyone managed to get the examples provided on Würth's github working with the arduino zero? I've spent most of today trying to figure it out  but after solving one error, another one pops up. I'm not familiar with platformio at all. first time using it. Also not familiar at all with the adafruit m0express or adafruit's way to "wrap" the samd mcu, so upon editing the platformio.ini provided in the examples i am met with lots of different errors. I've been chasing the errors one after the other, but after "solving" one, another one pops up, and it looks like this is deeply tied to the adafruit environment and using an arduino board with the examples will not be easy(at least for someone not very familiar with either arduino, not adafruit's environment, nor platformio)

looking at the "main" files in the example, i don't see why this is so deeply connected to adafruit's thing. the platformio.ini file "mentions"(i have no clue about the terminology) some libraries: easybutton, adafruit neopixel, and the extra libs section of the .ini also points to a bunch of libraries in the ..../common folder of the project.

any idea of where to start to migrate a platformio project from the m0express to the zero?

thank you!  

  • Sign in to reply
  • Cancel

Top Replies

  • balajivan1995
    balajivan1995 6 days ago +2
    The library seems like a fork of neopixel library. Have you tried using neopixel library instead?
  • michaelkellett
    michaelkellett 6 days ago +2
    I can't help you with Arduino things but I looked at the PlatformIO stuff on the web and found this: https://docs.platformio.org/en/latest/what-is-platformio.html I liked the bit that says: It…
Parents
  • michaelkellett
    michaelkellett 6 days ago

    I can't help you with Arduino things but I looked at the PlatformIO stuff on the web and found this:

    https://docs.platformio.org/en/latest/what-is-platformio.html

    I liked the bit that says:

    image

    It seems that the gulf between hype and real life is as big as ever. !

    Having said that, you can easily enough delve into the Wurth code on Github - it doesn't seem to be well explained which is all too typical of example code.

    (Almost all the explanation on the Github is about the tools and wrinkles of compiling the code rather than explaining what really goes on. A bit like giving someone a fish rather than teaching them how to catch their own.)

    If you can find the file ICLED_24bit.cpp you can see how it works.

    They use the SPI peripheral to output the ICLED data stream, packing two bits into each SPI output byte.

    Then they use DMA to output a packet of SPI bytes.

    Most people do it the same way (using SPI).

    For what its worth (possibly not much) here is some code I hacked together in a hurry a while ago to drive neopixels. It doesn't use DMA although I thought it might, hence the definition of some unused DMA stuff in lines 25 - 28.

    //
    //       FILE: dctrl_serial.c
    //  COPYRIGHT: 2024 MK Electronics Ltd
    //
    //     AUTHOR: MK
    //       DATE: 08/09/2024
    //     ORIGIN: New
    //
    //    PROJECT: Neopixel test on DCTRL
    //   HARDWARE: GD32E103C8
    // TOOL CHAIN: KEIL
    //
    
    
    
    #include "dctrl_project.h"
    #include "dctrl_main.h"
    #include "neopix_neo.h"
    #include "dctrl_gpio.h"
    #include "dctrl_serial.h"
    #include <math.h>
    
    // DEFNITIONS
    
    #define USART_DMA       DMA0
    #define RX_DMA_CHAN     4u
    #define TX_DMA_CHAN     3u
    #define USART0_DA  ((uint32_t)0x40013800u + 0x04u)
    
    #define BIT0    0x08u
    #define BIT1    0x0eu
    
    // GLOBAL VARIABLES
    
    uint16_t pix_buff[(N_PIX * 6u) + 2u];
    uint16_t pix_buff_size = (N_PIX * 6u) + 2u;
    uint16_t pix_buff_idx = 0;
    bool gb_pix_tx = false;
    
    
    
    
    void neopix_spi_init(void)
    {
        rcu_periph_clock_enable(RCU_SPI1);
        
        SPI_CTL0(SPI1) = 0x081cu;                       // master mode, pol = 0, pha = 0, baud divide  = 8 and SSM and SSI, 16 bit word
        SPI_CTL1(SPI1) = 0x80;                          // transmit buffer empty interrupt
    }    
    
    void NVIC_Configuration(void)
    {
       
        nvic_priority_group_set(NVIC_PRIGROUP_PRE0_SUB4);   
        nvic_vector_table_set (NVIC_VECTTAB_FLASH,0x0);     // Set the Vector Table base location at 0x08000000       
        nvic_irq_enable(SPI1_IRQn, 7,1);                    // preemption Priority = 7, Sub Priortiy = 1 
        
    }
    
    void SPI1_IRQHandler(void)
    {
        uint16_t sr;
        sr = SPI_STAT(SPI1);
        if ((sr & 0x02) != 0)
    	{
            SPI_DATA(SPI1) = pix_buff[pix_buff_idx++];
            if (pix_buff[pix_buff_idx] == pix_buff_size)
            {
                gb_pix_tx = false;
                pix_buff_idx = 0u;
                SPI_CTL1(SPI1) = 0x0;
            }
        }
    }
    
    bool neopix_start(void)   
    {
        bool reply = true;
        
        
        if (gb_pix_tx == false)
        {
            
            SPI_CTL0(SPI1) &= ~0x40u;
            SPI_CTL1(SPI1) = 0x80;
    
            SPI_CTL0(SPI1) |= 0x40;                         // start spi    
            gb_pix_tx = true;
        }
        else
        {
            reply = false;
        }
        
        return reply;
        
    }
    
                
    bool write_pix(uint16_t pix, uint8_t green, uint8_t red, uint8_t blue)
    {
        bool reply = true;
        uint32_t bin_data = (green << 24) + (red << 16) + (blue << 8u);
        uint16_t pix_idx = pix * 6u;
        uint8_t pix_word;
        uint16_t temp_word;
        uint8_t rgb_bit;
        
        if ((pix >= N_PIX) && (gb_pix_tx == false))
        {
            reply = false;
        }
        else
        {
            for (pix_word = 0; pix_word < 6u; pix_word++)
            {
                temp_word = 0u;
                for(rgb_bit = 0; rgb_bit < 4u; rgb_bit++)
                {
                    temp_word <<= 4u;
                    temp_word += ((bin_data & 0x80000000u) == 0u) ? BIT0 : BIT1;
                    bin_data <<= 1;
                }
                pix_buff[pix_idx++] = temp_word;
            }
        }
        
        return(reply);
    }
                    
    void neo_test(void)
    {
        pix_buff[pix_buff_size - 1] = 0;
        pix_buff[pix_buff_size - 2] = 0;
        write_pix(0, 0, 255, 0);
        write_pix(1, 0x0, 0x0, 255);
        
        neopix_start();
        
    }
    
    void neo_test2(void)
    {
        double x;
        double seed = 17342.4325086579478594365;
        double other_seed = 353.730953869873357895;
        uint16_t step;
        double intpart;
        uint64_t bigint;
        uint8_t col;
        uint8_t rgbs[6];
        
        pix_buff[pix_buff_size - 1] = 0;
        pix_buff[pix_buff_size - 2] = 0;
        
        for(step = 0u; step < 1000; step++)
        {
            x = seed / (other_seed + (double)step);
            x = modf(x, &intpart);
            x *= 2.81e14;
            bigint = x;
            for (col = 0; col < 6; col++)
            {
                rgbs[col] = bigint & 0xff;
                bigint >>= 8;
            }
            write_pix(0, rgbs[0], rgbs[1], rgbs[2]);
            write_pix(1, rgbs[3], rgbs[4], rgbs[5]);
                
            
            neopix_start();
            delay_us(500000);
        }
        
    }
    

    The comments in the code are not that helpful - sorry.

    MK

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • michaelkellett
    michaelkellett 6 days ago

    I can't help you with Arduino things but I looked at the PlatformIO stuff on the web and found this:

    https://docs.platformio.org/en/latest/what-is-platformio.html

    I liked the bit that says:

    image

    It seems that the gulf between hype and real life is as big as ever. !

    Having said that, you can easily enough delve into the Wurth code on Github - it doesn't seem to be well explained which is all too typical of example code.

    (Almost all the explanation on the Github is about the tools and wrinkles of compiling the code rather than explaining what really goes on. A bit like giving someone a fish rather than teaching them how to catch their own.)

    If you can find the file ICLED_24bit.cpp you can see how it works.

    They use the SPI peripheral to output the ICLED data stream, packing two bits into each SPI output byte.

    Then they use DMA to output a packet of SPI bytes.

    Most people do it the same way (using SPI).

    For what its worth (possibly not much) here is some code I hacked together in a hurry a while ago to drive neopixels. It doesn't use DMA although I thought it might, hence the definition of some unused DMA stuff in lines 25 - 28.

    //
    //       FILE: dctrl_serial.c
    //  COPYRIGHT: 2024 MK Electronics Ltd
    //
    //     AUTHOR: MK
    //       DATE: 08/09/2024
    //     ORIGIN: New
    //
    //    PROJECT: Neopixel test on DCTRL
    //   HARDWARE: GD32E103C8
    // TOOL CHAIN: KEIL
    //
    
    
    
    #include "dctrl_project.h"
    #include "dctrl_main.h"
    #include "neopix_neo.h"
    #include "dctrl_gpio.h"
    #include "dctrl_serial.h"
    #include <math.h>
    
    // DEFNITIONS
    
    #define USART_DMA       DMA0
    #define RX_DMA_CHAN     4u
    #define TX_DMA_CHAN     3u
    #define USART0_DA  ((uint32_t)0x40013800u + 0x04u)
    
    #define BIT0    0x08u
    #define BIT1    0x0eu
    
    // GLOBAL VARIABLES
    
    uint16_t pix_buff[(N_PIX * 6u) + 2u];
    uint16_t pix_buff_size = (N_PIX * 6u) + 2u;
    uint16_t pix_buff_idx = 0;
    bool gb_pix_tx = false;
    
    
    
    
    void neopix_spi_init(void)
    {
        rcu_periph_clock_enable(RCU_SPI1);
        
        SPI_CTL0(SPI1) = 0x081cu;                       // master mode, pol = 0, pha = 0, baud divide  = 8 and SSM and SSI, 16 bit word
        SPI_CTL1(SPI1) = 0x80;                          // transmit buffer empty interrupt
    }    
    
    void NVIC_Configuration(void)
    {
       
        nvic_priority_group_set(NVIC_PRIGROUP_PRE0_SUB4);   
        nvic_vector_table_set (NVIC_VECTTAB_FLASH,0x0);     // Set the Vector Table base location at 0x08000000       
        nvic_irq_enable(SPI1_IRQn, 7,1);                    // preemption Priority = 7, Sub Priortiy = 1 
        
    }
    
    void SPI1_IRQHandler(void)
    {
        uint16_t sr;
        sr = SPI_STAT(SPI1);
        if ((sr & 0x02) != 0)
    	{
            SPI_DATA(SPI1) = pix_buff[pix_buff_idx++];
            if (pix_buff[pix_buff_idx] == pix_buff_size)
            {
                gb_pix_tx = false;
                pix_buff_idx = 0u;
                SPI_CTL1(SPI1) = 0x0;
            }
        }
    }
    
    bool neopix_start(void)   
    {
        bool reply = true;
        
        
        if (gb_pix_tx == false)
        {
            
            SPI_CTL0(SPI1) &= ~0x40u;
            SPI_CTL1(SPI1) = 0x80;
    
            SPI_CTL0(SPI1) |= 0x40;                         // start spi    
            gb_pix_tx = true;
        }
        else
        {
            reply = false;
        }
        
        return reply;
        
    }
    
                
    bool write_pix(uint16_t pix, uint8_t green, uint8_t red, uint8_t blue)
    {
        bool reply = true;
        uint32_t bin_data = (green << 24) + (red << 16) + (blue << 8u);
        uint16_t pix_idx = pix * 6u;
        uint8_t pix_word;
        uint16_t temp_word;
        uint8_t rgb_bit;
        
        if ((pix >= N_PIX) && (gb_pix_tx == false))
        {
            reply = false;
        }
        else
        {
            for (pix_word = 0; pix_word < 6u; pix_word++)
            {
                temp_word = 0u;
                for(rgb_bit = 0; rgb_bit < 4u; rgb_bit++)
                {
                    temp_word <<= 4u;
                    temp_word += ((bin_data & 0x80000000u) == 0u) ? BIT0 : BIT1;
                    bin_data <<= 1;
                }
                pix_buff[pix_idx++] = temp_word;
            }
        }
        
        return(reply);
    }
                    
    void neo_test(void)
    {
        pix_buff[pix_buff_size - 1] = 0;
        pix_buff[pix_buff_size - 2] = 0;
        write_pix(0, 0, 255, 0);
        write_pix(1, 0x0, 0x0, 255);
        
        neopix_start();
        
    }
    
    void neo_test2(void)
    {
        double x;
        double seed = 17342.4325086579478594365;
        double other_seed = 353.730953869873357895;
        uint16_t step;
        double intpart;
        uint64_t bigint;
        uint8_t col;
        uint8_t rgbs[6];
        
        pix_buff[pix_buff_size - 1] = 0;
        pix_buff[pix_buff_size - 2] = 0;
        
        for(step = 0u; step < 1000; step++)
        {
            x = seed / (other_seed + (double)step);
            x = modf(x, &intpart);
            x *= 2.81e14;
            bigint = x;
            for (col = 0; col < 6; col++)
            {
                rgbs[col] = bigint & 0xff;
                bigint >>= 8;
            }
            write_pix(0, rgbs[0], rgbs[1], rgbs[2]);
            write_pix(1, rgbs[3], rgbs[4], rgbs[5]);
                
            
            neopix_start();
            delay_us(500000);
        }
        
    }
    

    The comments in the code are not that helpful - sorry.

    MK

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
Children
  • Anthocyanina
    Anthocyanina 4 days ago in reply to michaelkellett

    thank you! i'll look into your code in the morning. tonight after i got back from class i had a bit of an idea, and i got the build to be successful. i uploaded it to the zero, which was also successful, but the LEDs won't light up. i'll check tomorrow with the scope if there's any activity in the pins. thanks again! sorry about the late reply, busy few days! 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube