MikroElektronika Buggy: Arduino programming #2

0

So, after posting the Arduino IDE pin chart for the Clicker2 for PIC32MX, taking full advantage of the new chipKIT core v.1.3.1 it’s time now to revisit the Buggy. In this blog post I will publish an updated pin chart, and a new set of definitions to make the Buggy work in Arduino IDE.

This article is more than two years old and might contain obsolete information; it is still kept here for informational purposes.

So, first the pin chart, as usual available also in pdf format for download:

Buggy + Clicker2 for PIC32MX: Arduino IDE pin chart

Buggy + Clicker2 for PIC32MX: Arduino IDE pin chart

Advertisements

As one can see, this builds upon the previous pin chart for Clicker2 for PIC32MX, adding one extra level of pin definitions for the Buggy. Obviously, these definitions must be added to your Arduino sketch. I do prefer to put  these definitions is a separate header file, which is later included in the sketch:

/* BUGGY PIN DEFINITIONS
 * Software:  Arduino IDE v.1.6.12
 *            chipKIT core v.1.3.1
 *            http://chipkit.net/wiki/index.php?title=ChipKIT_core
 */

// PWM PINS
#define PIN_PWM_A       31
#define PIN_PWM_B       32
#define PIN_PWM_C       33
#define PIN_PWM_D       34
#define PIN_BC1_PWM     35
#define PIN_BC2_PWM     36
#define PIN_BC3_PWM     37

// INTERRUPTS
// NOTE: IN THE ORIGINAL DEFINITION FILE
// INT5 IS NOT DEFINED, SO WE HAVE TO DEFINE IT
#undef  NUM_INT_PINS    // might not be needed???
#define NUM_INT_PINS    6
#define PIN_INT5        12
#define PIN_BC1_INT     10  // INT3
#define PIN_BC2_INT     11  // INT4
#define PIN_BC3_INT     12  // INT5

// LIGHTS
#define PIN_LOW_BEAM    40
#define PIN_MAIN_BEAM   43
#define PIN_LEFT_SGN    9
#define PIN_RIGHT_SGN   39
#define PIN_BRAKE       38

// ANALOG PINS
#define PIN_BC1_AN      3
#define PIN_BC2_AN      4
#define PIN_BC3_AN      5
#define PIN_BATT_SENSE  6

// BATTERY AND USB STATUS
#define PIN_BATT_STAT   13
#define PIN_USB_SUPPLY  14

// COMMUNICATION PINS
// UART
#define PIN_RX          47
#define PIN_TX          48

// I2C
#define PIN_SCL         49
#define PIN_SDA         50

// SPI
#define PIN_SCK         72
#define PIN_MISO        73
#define PIN_MOSI        74

// CLICK#1 SPECIFFIC PINS
#define PIN_BC1_RST     20
#define PIN_BC1_CS      21

// CLICK#3 SPECIFFIC PINS
#define PIN_BC2_RST     8
#define PIN_BC2_CS      7

// CLICK#3 SPECIFFIC PINS
#define PIN_BC3_RST     42
#define PIN_BC3_CS      41

Just create an empty .h file and put the above definitions in it. Include the file in your sketch and you are ready to go.

Just to show you how simple is this, here’s a small sketch that blinks the lights:

#include "buggy_defs.h"

void setup() {
  // put your setup code here, to run once:
  pinMode(PIN_LOW_BEAM, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(PIN_LOW_BEAM, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(PIN_LOW_BEAM, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);
}

A few particularities

In the current board version for the Clicker2, the INT5 is not defined properly. As such, click boards placed in the rear socket might have problems when using interrupts.

Communication lines are shared between the click sockets. SPI will work fine, as there are separate CS lines for each click socket. I2C lines are also common to all mikroBUS sockets. Conflicts will appear if click boards having the same I2C address are used. UART lines are also shared by all click boards in the Buggy, as well by the mikroBUS socket #2 on the Clicker23 board. Only one click board that uses UART communication can be used.

There is a digital input pin that detects the presence of USB power for the socket on the Buggy. One can use this pin to stop the current program while power is applied to the Buggy (usually for charging the battery).

There’s a pin indicating charging status.There’s also an analog pin for reading the battery voltage.

Motors are driven by DRV8835. The truth tables for driving the motors are in the datasheet.

All pins except analog inputs are 5V tolerant.

Advertisements
Share.

Leave A Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: