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
Experimenting with Waterproof Connectors
  • Challenges & Projects
  • Design Challenges
  • Experimenting with Waterproof Connectors
  • More
  • Cancel
Experimenting with Waterproof Connectors
Blog Experimenting with Waterproof Connectors #4 Hybrid Coding with Arduino, Visual C# and Python for LettaPanda
  • Blog
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Experimenting with Waterproof Connectors to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: fyaocn
  • Date Created: 26 May 2023 6:39 AM Date Created
  • Views 428 views
  • Likes 9 likes
  • Comments 0 comments
Related
Recommended

Experimenting with Waterproof Connectors #4 Hybrid Coding with Arduino, Visual C# and Python for LettaPanda

fyaocn
fyaocn
26 May 2023

Hybrid Programming with Arduino,  Visual C# and Python for LettaPanda

Table of Contents

  • 1 Hybrid Coding
  • 2 Arduino Coding
  • 3 Visual C# Coding
  • 4 Python Coding
  • 5 Chain Them Together

1 Hybrid Coding

Hybrid coding is not always my first choice.

Since LettaPanda is hybrid architecture,

- Intel Cherry Trail Z8350 Quad Core Processor and  pre-installed with a full edition of Windows 10 Home Edition to run powerful tools such as Visual Studio, NodeJS, Java, Processing, and more.With existing APIs, develop projects on a LattePanda is the same as that on a normal PC - C#, Javascript, Ruby etc.

- ATmega Processor GPIO x 20 with Arduino IDE preinstalled.

- The OpenVINO runtime support Python API and C++ API.

Therefore, my only choice is hybride  Hybrid Coding with Arduino,  Visual C# and Python,

Refer to https://docs.lattepanda.com/content/1st_edition/hardware_introduction/ , Pinouts in area U1 are assigned to the X-Z8350 core, and Pinouts in area U2 are assigned to the ATmega32u4 core.Some pins have specialized functions:

  • Analog Inputs: A0 - A5, A6 - A11 (on D4, D6, D8, D9, D10, and D12). The LattePanda has 12 analog inputs, labeled A0 through A11, all of which can also be used as digital I/O (inputs/ouptus). Each pin has a 10 bit resolution (i.e. 1024 different values). By default, their voltages measure from ground to 5 volts.
  • Serial: D0 (RX) and D1 (TX). Used to receive (RX) and transmit (TX) TTL serial data.
  • External Interruptions: D3 (interrupt 0), D2 (interrupt 1), D0 (interrupt 2), D1 (interrupt 3) and D7 (interrupt 4). These pins can be configured to trigger an interruption when measuring low values, a rising or falling edge, or a change in value.
  • PWM: D3, D5, D6, D9, D10, and D13 provide 8-bit PWM output.
  • SPI: D16 (MOSI), D14 (MISO), D15 (SCK).
  • LED: D13 There is a built-in LED driven by digital pin 13.

2 Arduino Coding

Arduino coding according to https://docs.lattepanda.com/content/1st_edition/power_on/ and https://github.com/LattePandaTeam/.

Flash standard firmata for ATmega32u4 core to control Pinout in area U1 for motor control.

image

The board shall be selected as Arduino lenardo

image

The opensourced firmata using internal I2C bridging ATmega32u4 core with  Intel Cherry Trail Z8350 Quad Core.

Keep this code running , ready for next part of code.

3 Visual C# Coding

Download the LattePanda.Firmata class library for VIsual C#, that is only programming language for now.

Using Visual studio 2017, create new project rovingEye for motor control logic here in Visual C#, Refer https://docs.lattepanda.com/content/1st_edition/io_programming_reference/ for API.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using LattePanda.Firmata;
namespace rovingEye
{
    class Program
    {
        static void Main(string[] args)
        {
            string motormode;
            int motorduraion =200;
            Arduino arduino = new Arduino();
            arduino.pinMode(4, Arduino.OUTPUT);//Set the digital pin 4 as output   
            arduino.pinMode(5, Arduino.OUTPUT);//Set the digital pin 5 as output 
            arduino.pinMode(6, Arduino.OUTPUT);//Set the digital pin 6 as output 
            arduino.pinMode(7, Arduino.OUTPUT);//Set the digital pin 7 as output 
            //Console.WriteLine("Hello, rovingEye.");
            if (args.Length > 0)
            {

                motormode = args[0];
                if (motormode is "up") {
                    Console.WriteLine($"Direction={motormode}");
                    arduino.digitalWrite(4, Arduino.LOW);//set the LED off  
                    arduino.digitalWrite(5, Arduino.HIGH);//set the LED off    
                    Thread.Sleep(motorduraion);
                } else if (motormode is "down")
                {
                    Console.WriteLine($"Direction={motormode}");
                    arduino.digitalWrite(5, Arduino.LOW);//set the LED off  
                    arduino.digitalWrite(4, Arduino.HIGH);//set the LED off     
                    Thread.Sleep(motorduraion);
                }
                else if (motormode is "left")
                {
                    Console.WriteLine($"Direction={motormode}");
                    arduino.digitalWrite(6, Arduino.LOW);//set the LED off  
                    arduino.digitalWrite(7, Arduino.HIGH);//set the LED off    
                    Thread.Sleep(motorduraion);
                }
                else if (motormode is "right")
                {
                    Console.WriteLine($"Direction={motormode}");
                    arduino.digitalWrite(7, Arduino.LOW);//set the LED off  
                    arduino.digitalWrite(6, Arduino.HIGH);//set the LED off   
                    Thread.Sleep(motorduraion);
                }
                else
                {
                    Console.WriteLine($"Direction= No operaion.");
                }
                // Reset the motor to still for new command,
                arduino.digitalWrite(4, Arduino.LOW);//set the LED off  
                arduino.digitalWrite(5, Arduino.LOW);//set the LED off  
                arduino.digitalWrite(6, Arduino.LOW);//set the LED off  
                arduino.digitalWrite(7, Arduino.LOW);//set the LED off  
                Thread.Sleep(200);

            }
            return;
}

This part is simple, just parse the args and detect what command would be , than control Pins.

Build the project successfully

image

Run the exe file as expected.

image

4 Python Coding

Coding in Visual Code on OpenVINO venv Environment

image

Design the logic with python OpenVINO package

image

The following code can inject command to above exe file to run motor furward in "up" direction.

  import os
  p1="up" # only valid for up, down, left, right
  para= "%s %s" %("rovingEye",p1) #print (para)
  os.system(para)

5 Chain Them Together

Hybrid coding process is chain above codes one by one one Lettapanda, to make it roving Eye in hash environment.

  • Sign in to reply
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