Posts Tagged ‘ arduino

Getting started with Adafruit’s Circuit Playground Express

Overview

I’ve had a dream of authoring Python code directly on a microcontroller board for a long time.  That became a reality with MicroPython and the pyboard, but I didn’t jump in until my Circuit Playground Express (CPE, below) board from Adafruit showed up recently.

cpe <- CPE in bootloader mode!

This blog post is written as notes for my future-self, when I forget things.  But feel free to follow along reader…

I wrote this guide because despite the fact Adafruit has lot of data out there, it took me hours to sort through it all and figure out what applied, and what didn’t.


 

Circuit Playground Express Links


Required Hardware


Adafruit Setup Docs

It should be noted that I myself did all of these steps in the below order.  Which makes me wonder, for example, if the drivers & utils I installed during the Arduino section benefited later steps.  Each of these docs is broken out into more detail below The Bootloader section.

  • Circuit Playground Lesson #0 : Arduino Setup
    • This is authored for the “Circuit Playground” (the precursor to the CPE, it is a different thing), but docs still appears to apply.  Probably the best first place to start, but focused on Arduino.
  • MakeCode
    • If you want to try your hand at MakeCode programming on the CPE (Visual blocks, or JavaScript), start here.
  • CircuitPython Setup
    • This is actually a sub-doc for another tutorial, but explains how to setup CircuitPython on the CPE.
    • CircuitPyhon is based on MicroPython, with some differences.

The Bootloader

This CPE bootloader info applies to Arduino, MakeCode, and CircuitPython, so it’s worth calling out here.

Check the Bootloader:

  • Nice (MakeCode) overview here: “Downloading and Flashing“.  It should be noted that Arduino uploads via its own IDE, but you still need a bootloader to receive the data.  More info under “UF2 Bootloader Details“.
  • The first time you plug the CPE in over USB (before any other configuration / software installs), see if the bootloader works.  Press the reset button twice:  All the ring-LEDs should turn green, and D13 should be slowly pulsing.  The image a the top of this post shows this.
  • The issue I had is, the image in the linked docs don’t show the green LEDs:  Since mine were green, and the image of the docs were not, I thought I had a problem.  I did not.
  • IMPORTANT: Once the software is configured correctly (this started happening for me once I configured Arduino), entering bootloader mode should pop open a (Windows) Explorer.  However, the CPE has two different “Windows Explorer modes”:
    • “Bootloader Mode” : Again, all the LEDs should be red, and you should see a few files on it:
      • INDEX.HTM <- web link to the CPE
      • INFO_UF2.TXT  <- tells you about the bootloader
      • CURRENT.UF2  <- the current firware
    • “Program Mode” (I made that term up) : This is the the mode where you can drag & drop your programs onto the board.  This shows up on first time plug-in (usually takes 30 seconds or so for the Explorer window to pop open), or when you press the reset button once.  For example, with CircuitPython installed, I see these files:
      • /lib <- imported bundle libraries
      • code.py <- Main code to execute
      • boot_out.txt
  • Here’s a short video showing how the bootloader works:


Initial Arduino Setup

Based on Circuit Playground Lesson #0 : The links below are entirely from this tutorial, I’m just calling out some of the major points & gotchas.

I got the CPE with the goal of authoring Python code for it.  But based on all the initial documentation I could find, it seemed like Arduino was where one should start.

Install

  • From the docs for your OS: (Windows links below)
  • Add Circuit Playground to Arduino
    • (Obviously) follow all the steps here adding drivers and external packages.
    • This part really confused me for a bit (and Adafruit tech support to the rescue):  Be sure to choose the right board from Tools -> Board Menu.
      • The right board will be under the “Arduino SAMD (…) Boards” section, called “Arduino Circuit Playground Express”.  Any other board with a similar name (like, say, “Circuit Playground”) is wrong.  You’ll know it’s wrong because it won’t upload your sketch correctly.
      • See verbose errors and whatnot from my forum post here.
    • Once you’ve selected the correct COM port, you can then access:
      • Files -> Examples -> Adafruit CircuitPlayground  -> And choose a sketch therein for upload & test.
  • Other Notes:
    • During this process, I couldn’t get Arduino to connect.  After rebooting my machine and restarting the Arduino IDE, it asked me to install additional drivers, which I did.  Around that time things started working correctly.

Docs

  • The Arduino “Adafruit Circuit Playground Library Reference” can be found here.

Initial MakeCode Setup

Based on Adafruit’s MakeCode docs:  MakeCode provide a visual programming environment, JavaScript, all programmed in-browser.

Install

There really isn’t an “Install” per-say:  Just browse to : https://makecode.adafruit.com to open the editor.

You can now code in either the “visual blocks”, or JavaScript.

Presuming you can enter “bootloader” mode (discussed in the Arduino section above), once you save a .uf2 file from the MakeCode app, if you drag & drop it onto that open Explorer window, the window should close, and the app immediately run on your CPE.  Pretty slick!

I presume though, that some of those Arduino install steps were required, since my PC wouldn’t recognize the CPE as a USB device properly until then, which would have prevented me from dragging & dropping the .uf2 files onto it.

Docs


Initial CircuitPython Setup

From the Adafruit “Circuit Python Setup” docs (for the Metro M0 Express board, not that it matters so much).

This is the whole reason I got this hardware, so far, not disappointed!

Install

  • The above docs do a great job of covering it, but be sure you choose “Circuit Playground Express” options, since the tutorial was written for another board.
  • I flashed the CPE by just drag&dropping the downloaded ‘adafruit-circuitpython-circuitplayground_express-1.0.0.uf2’ (for CircuitPython 1.0, not 2.0, which at the time of this writing just came out and is in beta) file onto the CPE while in bootloader mode.  Note, it did take ‘a while’ for it to update, at one point I thought maybe it had broken.  But then it started working again.
  • I used the CircuitPython Blinky example to upload my first Python module, and it worked!
  • It appears that my current version of CircuitPython is running Python version 3.4.0.

Getting Bundles

  • CircuitPython ‘bundles’ Python libraries together for use on the CPE. Since the space on the CPE is so limited, sometimes you can only include specific compiled libraries with your module.
  • You can access the bundles here @ github: adafruit/adafruit_CircuitPython_Bundle
    • Don’t make the mistake I did:  Just grab (for example) the “adafruit-circuitpython-bundle-1.0.0-20170815.zip” file in the downloads section, not one of the individual libraries above:  They don’t have the ‘lib’ folder you need for transfer to the CPE.

Setting up a Serial REPL Editor

This is a great feature, that allows you to have a live Python interpreter running on the CPE.  This lets you query the board directly in a live coding session, awesome feature.  What is REPL you ask:  Answer here!

An overview of how to set this process can be found here: “Serial REPL“.

Other Info:

  • I used PuTTY for this connection.
  • It looks like the COM port for my CPE changes pretty often, so I have to access the Windows Device Manager every time I want to run this feature.  Mine shows up as “Teensy USB Serial”, and tends to bounce around COM9->11
  • You can’t connect when you’re in bootloader mode:  Get a program running first.
  • Note, on first time connect, you can’t connect in via REPL until the Windows Explorer (auto) opens:  That signifies that the machine is ready.
  • If, when the terminal screen comes up its black/no info, hit ctrl+c to break out of the running program and access the terminal: >>>
  • type help() to see a list of built-in functions.
  • You can use this same connection (before the ctrl+c) to see the output of any module currently running.

Docs


Really look forward to seeing what this little board can do!

Burning an Arduino Bootloader, reflashing Grbl

X-Carve has been working great, other than the fact the limit-switches only worked for one day:  On day one, they worked as expected.  But on day two, I installed Chilipeppr (which I’ve been continuing to use successfully), and they switches suddenly stopped working.  You can see my thread on the forums here talking about the issue.

After much discussion on that thread and others, it sounded like something was wrong with the Arduino Uno that shipped with the X-Carve.  No problem, I have two other Uno’s, I’ll just upload Grbl to them.  But the problem was, via the “Compile Grbl to the Arduino” page (based on this Inventables Grbl fork), it wouldn’t load.  Note, I’m on OSX 10.10.5

I would get these errors constantly:

avrdude: stk500_paged_write(): (a) protocol error, expect=0x14, resp=0x0d
avrdude: stk500_cmd(): programmer is out of sync

And sometimes this:

avrdude: stk500_recv(): programmer is not responding

Super frustrating.  After more searching, it sounded like the bootloader on the older Uno’s was out of date, and I needed to update it.  I’ve done a lot of Arduino programming in the past, but never had to burn a bootloader.

Arduino has a tutorial here:  Arduino as an ISP  :  It shows how you can use Arduino A to act as an ISP (in-system programmer) for Arduino B.  Problem is, I couldn’t get it to work.  Followed the directions perfectly, but would constantly get errors.

After more searching online, I found reference to “Atmega bootloader program by Nick Gammon”:

I downloaded the source sketch, followed the directions, and it worked!  The only gotcha was, after I uploaded the sketch, I had to open the Serial Monitor to see all the text listed under the “Example Output for Uno” section (that wasn’t terrible obvious for me to do based on the instructions).  I was then able to issue the remainder of the commands, and complete the burn.  So a huge thanks to Nick Gammon!

Once the bootloader was re-burned, I was able to “compile Grbl to Arduino” per the above link, and it actually worked.

But, querying the default grbl values via the $$ command looked really weird.  I learned you need to issue this command to reset to factory defaults:

$RST=$

In addition, programs like Chlipeppr and UGS won’t send the ‘?’ command to grbl over their serial connection (which you need to print your limit switch settings) : I had to issue that via the Arduino IDE’s Serial Monitor.

I was able to test voltage on the digital pins for the limit-switches (D9, D10, D12), and they all had positive voltage, meaning they now work.

But unfortunately, it wouldn’t work in the X-Carve.  From my forum thread above:

Update on this: I checked the digital pins on the new grbl loaded uno: They all read close to 5v, which tells me they should actually support the limit switches. So that’s good…

However, the whole thing doesn’t work: Even though (on the ‘old but updated Uno’) I can query the grbl firmware vals from both the Arduino IDE & from the ‘Advanced settings’ in Easel, when I go to do the machine setup, I can’t jog the steppers at all. No sounds, nothing. I unplugged the limit-switches, but that didn’t make a difference. Swap for the ‘shipped with x-carve’ uno\gshield combo and it scoots all over. Swap back to the ‘old but updated’ uno\gshield, and dead in the water.

Comparing my ‘old but updated’ uno to the ‘shipped with x-carve’ uno, I notice the x-carve one has more header pins the gshield plugs into. At this point I’m guessing that Arduino Uno’s aren’t created equal, and the other ones I have are ‘just too old’.

Maybe I’ll get around to buying a ‘newfangled uno’ eventually, but since right now I’m cutting just fine without the limit-switches, that’ll be a future project. Thanks for all the help though!

SOOOOOooo… no limit-switches for me right now.  But at least I can still carve :)

X-Carve CNC learnings : MeshCAM, touchplates, Chilipeppr, & multi-pass cuts

It’s been great having two weeks off over the holidays, and a newly assembled X-Carve.   Following up on previous posts, this is more learning, saved on the web for my future reference.  Current CNC skill level = noob.

MeshCAM

meshCAMWhile Inventable’s Easel ($ = Free) is great, I’ve quickly exhausted it’s capabilities.  Specifically, I want to model 3d objects in Autodesk Maya, and mill them on my X-Carve.  Currently Easel does 2D (cutouts) 2.5D (cutouts at multiple heights) but not full 3D objects.  Reading the forums there appears to be several popular software packages out there that do what I’m after, two of which include MeshCAM ($250-$500) and VCarve ($350-$700).  My issue is I’m on a mac, which is very limiting in the world of CNC as I’ve learned, so I can’t even test V-Carve :-(  MeshCam it is!

MeshCAM does give you a nice fully featured trial period (couple weeks) to check it out.  And it does exactly what I’m after:  Creates multi-pass (roughing, finish) toolpaths based on my 3d objects.  Pros is that it does that well!  Cons is that the UI feels a bit antiquated compared to most 3d software I use, and I can’t really find any robust instructions online (they do email you a tutorial a day once you get the trial though).  But it gets the job done.

List of tutorials I’ve found:

Other Links:

And, it exposed the first issue that prompted this whole post:  Since it provides for multi-pass cuts (requiring a tool change), how can I actually implement them?

Touchplates

To dotouchplate a multi-pass cut (as I’ve been learning), you generally use a big fat bit on the roughing pass to remove a bunch of material, then a finer bit on the finish pass to make it look all nice.  But this obviously means you need to swap bits.  And if you swap bits, how can you guarantee that the Z-height is the exact same on the finish pass as it was on the roughing pass?  Since when you remove bitA and add bitB, there’s no way a human can guarantee the tip of bitB is at the exact same location that bitA’s was.

Reading the forums it quickly became apparent that I needed a ‘touchplate’ : A chunk of metal of a known thickness you can use to effectively ‘close a circuit’ with the spindle bit:  When that circuit is closed, you know you’ve hit the top of the material you’re about to mill (with the bit a known distance above it).

I fashioned my touch-plate out of a scrap of 1/8″ aluminum my father had given me from a previous boat build:  Drilled a small hole in one end, affixed a wire to it through a bolt tapped into it.

From there, per the forums, I connected that to the Arduino Uno’s A5 pin, and another wire with an alligator clip on the end to it to the gShield’s ground.  The main issue is the analog headers on the Arduino are hard to get at because of the gShield on top, but I was able to get a small lead plugged in (see below image).

wiring

But once it was all wired up, how to test, and ultimately use?

ChiliPeppr

ChiliPepprchillipeppr is something I only recently learned about:  A tool for sending gcode to your device, supporting tinyG and Grbl (which the X-Carve uses), and ‘generic serial’. The Universal GcodeSender (Grbl only?) was a close second (and I got it up and running, which required a frustrating update of Java on my mac), but honestly ChiliPeppr just looks cool while you’re using it.  While Easel allows you to send gcode to the gShield, I couldn’t actually get it to execute the (below) touchplate gcode:  The machine would just make a weird vibrating sound.  Could be my complete lack of knowledge on the subject, and I wanted to learn how to use ChiliPeppr anyway.

The first stumbling block was figuring out how to connect ChiliPeppr to my X-Carve (since there are no instructions for ‘first time users’ I could find) : As it turns out, based on the smallish screen of my Macbook Air, the menu on the bottom right that lets you “Download Serial Port JSON sever” wasn’t visible.  You need to install and run that server (a shell pops up to let you know its running) to allow ChiliPeppr to talk to the X-Carve.  Once that was done, I was in business.

One thing I’ve noted about ChiliPeppr every time I’ve used it to make a cut (total of three times now) : It seems to randomly pause.  I have to “unpause” it, and it happily goes along it’s way.  Not sure what is causing this, nor can I find any errors/warnings shown.

Other ChiliPeppr links:

Multi-Pass Cuts

Being the CNC noob that I am, since I couldn’t find any docs for this (meaning, using a combo of MeshCAM, Chilipeppr, and doing multi-pass, tool-changing cuts) anywhere.  So below is a rough outline of my experience doing just that:

  • In MeshCAM I created both a rough and finishing pass, and saved out the gcode using the “Shapeoko GRBL-Inch” postprocessor.
  • I drag & dropped that .nc file into ChiliPeppr.
  • In ChiliPeppr, I used the jog controls to move my toolhead to the bottom-left corner of where I wanted the cut to start.
  • Using the touchplate, I put it under the toolhead, connected the alligator-clip to the it, then created a ChiliPeppr JavaScript macro:
    • macro.sendSerial(“G20\n G92 Z0\n G38.2 Z-.5 F1\n G92 Z.124\n G0 z.25”);
    • The above (modified) code is thanks to a X-Carve forum post by user CharleyThomas.  The raw code on a single line looks like:
    • G20; G92 Z0; G38.2 Z-.5 F1; G92 Z.124; G0 z.25
      • G20 : set to inches
      • G92 Z0 : Zero the Z axis, I added this later:  Before I added this, there was a bug that the first time I’d run the macro, the toolhead would go up, not down.  There was some speculation that since the coordinate system wasn’t set yet, the machine thought the toolhead was too low, and would auto-raise it.  Regardless of the issue, this command solved it.
      • G38.2 Z-.5 F1 : Move the spindle down half an inch max looking for the touchplate
      • G92 Z.124 : Set the z-height to the thickness of the touchplate (mine is .124″)
      • G0 z.25 : Raise the spindle to 1/4″ above the material.
    • Note, as I was authoring this, I realized ChiliPeppr has a ‘Touch Plate’ widget, but I have yet to investigate it.
  • From there I turned on the spindle, and fired off the gcode.
  • When it paused for toolchange, I swapped the bit, then re-executed the above steps with the touchplate and macro to re-zero the z-height.  Then unpaused it to continue the work.

Worked like a charm:

final_pass

In the above pic you can see the finish pass emerge from the rough.

All in all, a pretty rewarding experience.

 

X-Carve : Configuration & troubleshooting

This page will be an evolving repository for myself, to collect bits and pieces of X-Carve configuration, troubleshooting, etc.


Configuration

Steps per mm

After I built the X-Carve and got a few test cuts in, I found it odd there was no tuning step.  With 3d printers, it’s important to make sure you get their “steps per mm” set so when you say “make this 10cm”, it really is 10cm.  I found the “Calibration Test Pattern” project and started cutting.  Immediately I noticed something was wrong:  The circle (labeled #13) it started with was an oval, not a circle.  After searching the forums, I found this great vid showing how to calculate the steps per mm (just about the exact same process as on a 3d printer), and how to update the settings via Easel:

As it turns out, my Y & Z seemed pretty spot on, but my X was way off.  Fixed!

Motor current

Just like on 3D printers, you need to tune the steppers current so it’s not too little (so that you miss steps) or too great (so you miss steps).    All three of my stepper pots were off from the factory (which is normal, really), and to get started I manually twisted the pots until they started behaving correctly.  But I figured there was a more accurate way, like tuning the stepper drivers on my C-Bot.  And there is: Again, another great vid:

I have the Nema 23’s from inventables, which are 2.8A per phase.  Using the method from the above vid I set them all to 2V.   Seems to work just fine so far.

Troubleshooting

Forum post with a variety of troubleshooting videos:

https://discuss.inventables.com/t/x-carve-maintenance-troubleshooting-videos-add-your-own/13405/5

Understanding GRBL

I somehow got my limit switches broken.  Follow the thread here for the nitty gritty.  As of this authoring they still don’t work:  Worked fine for a day, and then… dead:  Those pins on the Arduino constantly read 0v.  But in the process of debugging this I learned a lot about grbl.

This forum post got me started on talking to grbl.

The easiest way for me to talk with grbl is through the Arduino IDE.  It was a little twichy at first, here’s what I had to go through:

  • Make sure your board is set to Arduino Uno (since right now grbl requires an Uno).
  • Make sure you have the right port selected (obviously).
  • When the serial monitor is up, make sure your baud rate is 115200.
  • If it connects properly, you should see it say something like > Grbl 0.9j [‘$’ for help]
  • You issue commands to grbl by prefixing them with the dollar sign: $.  If you issue the $ command and nothing happens, change the baude rate to 115200 again.  I had to connect a few times before it would let me issue commands to it.

grbl links:

First steps with the Adafruit Trinket

I recently picked up a Adafruit Trinket (3.3v), simply because they’re so cheap (about $8).  I like the idea of a tiny small Arduino-ish board.  Since I’m forgetful, below documents the overall process I got to get it working.

End result:  Franken-servo!

End result: Franken-servo!

Resource Links:

First Steps:

For all the documentation on the web, I really wasn’t sure where to start.  There’s all this talk of installing AVRDUDE, etc, but as it turns out it’s really not needed (if using the Arduino IDE). Here’s the streamline approach I finally took:

  • Setup my pre-existing Arduino IDE for use with the Trinket, following these Adafruit docs.
  • Since I’m on a Mac, I didn’t have to worry about installing any drivers, but the “Mac Arduino IDE” app download they provided didn’t work.  Mac said it was “corrupted”.  So instead I had to use the “Slow Way” example they gave.  And other than a few path differences it worked just fine.

Programming:

  • I was able to successfully run all their examples from the page “Programming with Arduino IDE“.
  • Earlier in the day I had done some servo programming on an Arduino, and I wanted to emulate it on the Trinket.  Thanks to the “Trinket Servo Control” tutorial, and their “Adafruit SoftServo” library, I was able to make it happen.  However, I was unable to create two separate servo objects:  I think I don’t quite grasp the Trinket pinouts.  The above image has two servo’s hooked up to the same pin, so they move the exact same way.

So a successfully first attempt.  Next up, I really need some batteries to make a standalone project with it…