Giter Club home page Giter Club logo

cultivatarmobile's Introduction

Cultivatarmobile

The Cultivate Robot, aka The Cultivatarmobile, is a fun project to get started in developing hardware applications using Nerves - the embedded Elixir project. The project gives you a small buggy, powered by two (admittedly slow) Stepper motors which can be controlled directly over a web interface or via Slack.

Kits are to be given as prizes at Elixir London 2016, but you can fairly easily build your own.

Parts

A pictorial representation of the parts is here. Here are the electronic parts with some UK sources, though bear in mind that stock can vary per supplier and URLs can change.

Part Available from
Pi Zero (only) PI Hut: https://thepihut.com/products/raspberry-pi-zero?variant=14062715972, or Pimoroni: https://shop.pimoroni.com/products/raspberry-pi-zero/ Note that stocks are limited to one per customer.
WiFi dongle eg https://thepihut.com/products/usb-wifi-adapter-for-the-raspberry-pi, https://shop.pimoroni.com/products/official-raspberry-pi-wifi-dongle
40-pin 2x20 male headers for the Gpio https://shop.pimoroni.com/products/male-40-pin-2x20-hat-header
USB to micro USB adaptor This USB to microUSB OTG Converter Shim from The PI Hut is great: https://thepihut.com/products/usb-to-microusb-otg-converter-shim
Female / Female jumper cables At least 10, eg from https://www.amazon.co.uk/gp/product/B00OL6JZ3C/
5v power bank (portable phone charger) Something like https://www.amazon.co.uk/gp/product/B00VJS9R4C. They should come with a USB to micro USB cable to connect to the PI
Micro SD card, at least 4GB Bigger is ok. eg https://www.amazon.co.uk/Kingston-8GB-Micro-SD-HC/dp/B001CQT0X4/
2 x 28Byj stepper motors with ULN2003 controllers eg 5 pieces from here https://www.amazon.co.uk/gp/product/B00SSQAITQ
Battery for stepper motors For the giveaway we a used battery holder for 4 AA batteries, https://www.amazon.co.uk/gp/product/B00XHQ18DW. You need to provide between 5v and 12v to the steppers
Wheels 4tronix, a UK company, sell wheels that fit the stepper motors http://4tronix.co.uk/store/index.php?rt=product/product&keyword=wheels&category_id=0&product_id=176. Alternatively here's some 3D printing files that I have found http://www.thingiverse.com/thing:862438

Of course you do not have to use a PI Zero. Any PI (or other supported Nerves target) should work. You may need to slightly modify apps/fw/mix.exsfor other targets.

If you are in the USA, then you may find this Amazon wish list put together by Joel Byler useful.

Soldering

PI Zeros come without a means of securely attaching wires to the GPIO which is used to control the motors. If you use a PI Zero, then you'll want to solder on some GPIO headers. Here is one video on how to do it: https://www.youtube.com/watch?v=MSGIrtGMYRM

Another thing you will probably need to solder is the connection from the batteries to the power input of the ULN2003 stepper motor controller. We suggest connecting each the positive and ground to two female-ended jumper cables. See the illustration of the battery case in the parts illustration.

Chassis

We used Lego to build the chassis, connecting the power bank and PI by attaching Lego to them with Sugru. We will publish a list of bricks at some point. All you need is a container to which you can attach the two wheels and to hold the rest of the parts. Something low friction for the back is useful too.

Connecting the drive together

  1. Connect each of the stepper motors to the ULN2003 controllers; the connection is obvious and will only be connectable in one direction. Depending on your chassis, you may want to cable tie the motors back to back.
  2. Connect the ULN2003 controllers to the raspberry PI. Refer to a pin map such as this from Element 14; the SD card on the PI zero is at the top of the map. The actual pin mapping is changeable in the configuration, but the default configured mapping is
    • GPIO 6 to IN1 on the left ULN2003 controller
    • GPIO 13 to IN2 on the left ULN2003 controller
    • GPIO 19 to IN3 on the left ULN2003 controller
    • GPIO 26 to IN4 on the left ULN2003 controller
    • GPIO 12 to IN1 on the right ULN2003 controller
    • GPIO 16 to IN1 on the right ULN2003 controller
    • GPIO 20 to IN1 on the right ULN2003 controller
    • GPIO 21 to IN1 on the right ULN2003 controller
  3. Connect the positive (marked '+') pins on both ULN2003 controller to the positive terminal of the battery case.
  4. Connect the negative (marked '-') pins on both ULN2003 controller to the negative terminal of the battery case.

Note that some motors appear to be wired in reverse; if you find one (or two) going the opposite way to expected then simply reverse the wiring to the controller.

Configuration

You will need to add a Slack token for your Slackbot, and set the SSID and password for your WiFi network.

cp apps/cb_slack/config/secret.example.exs apps/cb_slack/config/secret.exs 
cp apps/fw/config/secret.example.exs apps/fw/config/secret.exs 

Create a Slack Bot User and replace the placeholder inapps/cb_slack/config/secret with the bot user's token.

Replace the placeholders in apps/fw/config/secret.exs with the details of your Wifi network.

Building on your machine and testing

In a slight departure from normal Nerves practice, all the applications in the umbrella project are configured to be run on a host machine (such as a Mac) in dev and test modes. See the blob post here.

Building for the firmware image must be done with MIX_ENV set to prod.

From the Umbrella application route you should be able to run.

mix test

All the tests should pass. You can also run tests for each umbrella application in that applications directory.

You can also run

iex -S mix

Your Slack Bot User should connect to your slack. You can say "cultivate help" in a channel to which your user has been invited, to receive the help message. Navigating to http://localhost:4000 should bring up the web interface.

Deploying to your PI Zero

Ensure that you are set up and up to date for Nerves environment by following the instructions here

cd apps/fw
MIX_ENV=prod mix compile
MIX_ENV=prod mix firmware

Ensure your SD card is inserted to an attached SD card writer.

MIX_ENV=prod mix firmware.burn

Insert the SD card to the PI. If all has gone well, then booting the PI should connect to your network and Slack.

The Code Structure

This is an Umbrella project containing the applications below. More details of each project may be in the project's README file.

This is the "master application" used to make the firmware releases. At the time of writing, Nerves uses Exrm to produce releases, and the Exrm convention is to have an application from which to build them. It is not an entirely dumb application; it is responsible for:

  • networking, ie connecting to WiFi
  • setting the time via NTP
  • somewhat insecurely, making this Cultivatormobile instance a distributed Erlang node, with the name "CultivatarMobile@[IPV4 address]".

Controls the stepper motors, through the named GenServer CbLocomotion.Locomotion.

Provides the Slack interface to the Cultivtormobile. Remember to set your Slack token in apps/cb_slack/config/secret.exs (see configuration instructions above.)

Provides the web interface to the robot. It listens on port 80 in production (on the device) and port 4000 in development mode.

Provides fake versions of hardware specific code in development and test. This allows compilation on non-linux host environments, and (in the case of GPIO) ways of checking value changes in tests.

cultivatarmobile's People

Contributors

onekelvinsmith avatar paulanthonywilson avatar scott-ad-riley avatar spencer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

layeddie

cultivatarmobile's Issues

Problem compiling erlware_commons

Got the following error when compiling cultivarmobile:

** (Mix) Could not compile dependency :erlware_commons, "/Users/ellis/.mix/rebar3 bare compile --paths "/Users/ellis/Robot/cultivatarmobile/_build/dev/lib/*/ebin"" command failed. You can recompile this dependency with "mix deps.compile erlware_commons", update it with "mix deps.update erlware_commons" or clean it with "mix deps.clean erlware_commons"

I had add updated dependencies for relx and erlware_commons:

diff --git a/apps/fw/mix.exs b/apps/fw/mix.exs
index d7afbbe..44d5cbf 100644
--- a/apps/fw/mix.exs
+++ b/apps/fw/mix.exs
@@ -31,6 +31,8 @@ defmodule Fw.Mixfile do
   def deps do
     [
       {:nerves, "~> 0.3.0"},
+      {:relx, "~>3.23.1"},
+      {:erlware_commons, "~> 1.0"},
       {:nerves_interim_wifi, "~> 0.0.2", only: :prod},
       {:cb_slack, in_umbrella: true},
       {:cb_web, in_umbrella: true},
diff --git a/mix.lock b/mix.lock
index b768ccd..7b8806b 100644
--- a/mix.lock
+++ b/mix.lock

and that fixed the build.

(Elixir 1.5.1, Erlang 20.0, git ref 0914846)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.