Random Ramblings on LabVIEW Design

Community Browser
Labels
cancel
Showing results for 
Search instead for 
Did you mean: 

Re: LabVIEW Firmata - Easy control of Arduino Microcontrollers

swatts
Active Participant

Hello Lovers of cheap hardware,

Wanna spend $20 and get AnIns, Digital Outputs and Digital Inputs, this is the article for you.

 

First the hardware.

If memory serves the LattePanda V1 has an Arduino Leonardo on it, this is based on ATmega32u4 (datasheet), this is what I bought Arduino Leonardo.

I then loaded the very nice Arduino IDE and load some of that weird text stuff onto the device. Instructable Instructions here.

 

And now things get annoying, information on this very simple protocol was sadly lacking or of dubious quality. Rather than just show example messages and returns I had to dig through code and then test the mapping to the controller pins. Some of this is just the nature of micro-controllers (every pin does a thousand different things!). Some of it is the nature of Open-source projects.

 

To make things simple I just implemented enough to make it useful for our projects. So 6 x 10 bit analog inputs, 4 digital inputs and 5 digital outputs. I tried to avoid some of the communication and control pins for the future.

 

The following image shows what's what and where.

 

swatts_0-1708420815366.png

 

To try and document the pins and messages better I built little message generators. Code will be attached (LV2020)

 

swatts_0-1708108887368.png

swatts_6-1708109667131.png

 

I also made some helper VIs to for mapping the pin numbers (they change for different functions!)

 

Next you need to decipher the returned bytes.

 

Thanks to KMurphs https://github.com/KMurphs/labview-client-for-firmata for saving me time on some of the conversion stuff, it's always a pain.

 

swatts_7-1708109917612.png

Attached is a project example and this shows how it all goes together.

 

swatts_8-1708110010343.png

 

Here's a video of it working.

 

The attached project is written in LabVIEW 2020.

 

PS: I have now tested it on the LattePanda Delta V3 and it all works very nicely. The next job is to get SQLite working in Linux, so I can build a template for projects.

 

 

Lots of love

Steve


Opportunity to learn from experienced developers / entrepeneurs (Fab,Joerg and Brian amongst them):
DSH Pragmatic Software Development Workshop


Random Ramblings Index
My Profile

Comments
Thoric
Trusted Enthusiast

Really great work Steve. Keep going! 💪

Thoric (CLA, CLED, CTD and LabVIEW Champion)


swatts
Active Participant

Just got SQLite going on the LattePanda, so that's my company template sorted. It's all going very well.

Steve


Opportunity to learn from experienced developers / entrepeneurs (Fab,Joerg and Brian amongst them):
DSH Pragmatic Software Development Workshop


Random Ramblings Index
My Profile

Jason1029
Member

Hi, interesting configuration - and pretty much what I've been looking for!  Thank you for posting this!

 

Having downloaded the zip file and loaded an Arduino Uno with FirmataStandard - so far the digital outs and analog ins are working, but the digital ins and Firmata firmware data are not coming in.  Being new to all these bits (but being familiar with other programming languages) I'm just wondering what you might suggest as the likely culprits might be ...

 

Thanks.

swatts
Active Participant

Hi Jason,

I don't know what the difference is between the Uno and the Leonardo.. maybe that's it.

Without checking out your system I can't help much in the comments... if you DM me and wanna zoom I'm sure it can be arranged.

 

(If I can remember how to program the Arduino....)

 

My colleague did make a couple of changed to the code to improve the analog input stability. I've not had time to modify the code yet.

Steve


Opportunity to learn from experienced developers / entrepeneurs (Fab,Joerg and Brian amongst them):
DSH Pragmatic Software Development Workshop


Random Ramblings Index
My Profile

Jason1029
Member

Will do Steve, thank you!  I'll DM you in a bit.  Looking forward to finding and resolving the bug(s) so this configuration can be utilized by other new users with an Arduno Uno as a starting point.

swatts
Active Participant

Just so the world knows, it appears that the UNO is a bit slow and the initialisation part of the example confuses it. We slowed that part down with some "waits" (shudder) and all became useable.

 

I've ordered an UNO to have a tinker with, see if I can make the example code a bit more wholesome.

 

Nice to meet you Jason.

Steve


Opportunity to learn from experienced developers / entrepeneurs (Fab,Joerg and Brian amongst them):
DSH Pragmatic Software Development Workshop


Random Ramblings Index
My Profile

Jason1029
Member

Steve, many thanks for walking me through the block diagram and helping to get this configuration working with the Uno.  Even with required initialization delays this one-of project can now move forward.

 

Question - I've been adding and moving some of the digital pins around and have come up against another challenge.  The goal was to make D2-D7 DIs and D8-D13 DOs (just to keep the I/O port mapping together).  All other changes seem to have gone smoothly (reassigning pins, duplicating event cases) but for some reason D11 is odd man out and it's not on this pull-down list:

 

D11.PNG

 

Thoughts?

Jason1029
Member

Another anomaly with the pulldown list are D14 and D15.  They don't exist on the Uno - so - where was this list created and how is it edited?

swatts
Active Participant

It might be as simple as a typo Jason, easiest test is to modify it and see if it works. (report back if it does, I'll correct it and take the plaudits)

 

I'll wait for my UNO to arrive and then have a good look at the code. Probably next week now.

 

With regards to the enumerated type (enum) it purely enforces a pin/channel in pin.vi (I was expecting some abstraction to be required here and I like to limit possibilities with the use of enums). If you don't want them, feel free to delete them.

 

 

 

 

Steve


Opportunity to learn from experienced developers / entrepeneurs (Fab,Joerg and Brian amongst them):
DSH Pragmatic Software Development Workshop


Random Ramblings Index
My Profile

Jason1029
Member

Thanks for the pointers Steve.  Ended up ferreting my way back to pin.ctl where the list was defined.  Changed D14 & D15 to D3 and D11 and moved these entries into their appropriate locations in the list.

DOs 8,9,10,12,13 work as expected - but not 11

DIs 2,4,5 work - but 3 triggers 2, 6 triggers 5&6 and I get no response from 7.

 

{sigh}

Jason

Jason1029
Member

Further to the previous message, on the BD in the Initialize Device, under Selector Label 1, changed the input list of the PINMODE signal to D2-D7, and under Selector Label 3 changed the output list of the PINMODE signal to D8-D13.  In the Event Loop removed the D7 Event Case.  Also revised the x90 Case Structure inside the Firmata Q Loop - Front Panel response remains unchanged ...

 

swatts
Active Participant

I have an Uno now, will look at code this week.

Steve


Opportunity to learn from experienced developers / entrepeneurs (Fab,Joerg and Brian amongst them):
DSH Pragmatic Software Development Workshop


Random Ramblings Index
My Profile

swatts
Active Participant

"Thanks for the pointers Steve.  Ended up ferreting my way back to pin.ctl where the list was defined.  Changed D14 & D15 to D3 and D11 and moved these entries into their appropriate locations in the list.

DOs 8,9,10,12,13 work as expected - but not 11

DIs 2,4,5 work - but 3 triggers 2, 6 triggers 5&6 and I get no response from 7."

 

The Leonardo uses D0,D1,D3 and D11 for other things, so the Firmata mask doesn't implement them in it's standard form (i.e. the firmware is written to ignore them), this is show in the image loaded on the Front Panel.

 

I'll now dig around in the documentation and see what is written for the UNO.. It's the nature of microcontrollers to have all these multi-function pins but some are best suited to certain duties.

Steve


Opportunity to learn from experienced developers / entrepeneurs (Fab,Joerg and Brian amongst them):
DSH Pragmatic Software Development Workshop


Random Ramblings Index
My Profile