Skip to content

Phinally! (In Which I Get the Pimoroni Explorer PHAT working)

November 30, 2018

A while ago I bought a little circuit board that seemed perfect for the Olduino/370 Carbot.  It fits onto the Raspberry Pi Zero and provides motor drivers, analog-digital conversion, and buffered 5v i/o.  I put it aside because it started to seem like too much trouble to work with: it uses chips i’m not familiar with, all the examples and libraries are in python rather than C, and it sits over all the GPIO pins making it hard to connect other peripherals. (I’m a fan of python but i’m integrating with the C code base of Hercules and wiringPi so its’ just an added headache to convert).

Today, though, everything clicked into place.  The interfaces I need are:

  • The motor driver pins
  • The ADC converter

I got the motor driver pins figured out finally by running a python example and checking the state of the likely seeming pins.  I was quickly(well, not quickly) able to identify the left hand motor pins as 24&28, and the right hand pins as 25&29. i.e. if 24 is high and 28 low, the left motor runs forward full speed; reversing those causes the motor to run backwards; and pwm-cycling the high pin can modulate the speed.  These results are solid but they’ll have to be adjusted for final wiring.

#!/usr/bin/env python
import sys
import explorerhat as eh
def setmotor(m2,m1):
  if (m1>=0):
  if (m2>=0):
while(line != ''):
  if line.startswith('0'):
  elif line.startswith('1'):
  elif line.startswith('2'):
  elif line.startswith('3'):
  elif line.startswith('-'):
  elif line.startswith('!'):

I’m reading the ADS1015 analog-digital-converter through an extension of wiringPi meant for the very similar ADS1115. The trickiest bit is that the 12 bits returned by the ADC get munged by the wiringPi code which expects 16 bits. I forget how i came to this but the answer was to readjust the result provided by wiringPi after the fact. Also, the ADS1015 is 4 channels but I’ve only found the channels labelled “1” and “4” available as analogRead(3) and (0) respectively.

//ads1015 test raspi adc from explorer phat
#define MY_BASE 2222
void main(){
  float v;
  ads1115Setup (MY_BASE, 0x48) ;
  int ch0 = analogRead (MY_BASE + 0) ;
  int ch3 = analogRead (MY_BASE + 3) ;
  printf("ch0 sez %d\n",ch0);
  printf("ch3 sez %d\n",ch3);
  if (ch3>0x7ff0) ch3-=0x10000;
  if (ch0>0x7ff0) ch0-=0x10000;
  printf("channel 0 voltage is %f\n",((float)(ch0>>4)/0x7ff)*5.0);
  printf("channel 3 voltage is %f\n",((float)(ch3>>4)/0x7ff)*5.0);

Bundling this for execution meant simple changes to the wiringMVS.c code that gets copied into general2.c of the Hercules emulator.

//18-11-23 remove automatic inline setup calls
//         comment out most verbose msgs
//18-11-30 changed analogread setup and code to use the ads1115 extension rather than MCP3002
#define SPI_CHAN        0
#define MY_PIN_BASE     5555    // Anything >= 64
int wiringMVS(int function, int parameter){//implements wiringPi functions for MVS
	static int mcp3002_pinbase=0,wiringPiSetuped=0;
	int result=0;
	//printf("wiringMVS sez: function=%x,parameter=%x, setup@%X=%d\n",function,parameter,&wiringPiSetuped,wiringPiSetuped);
	switch (function){
		case 0:	//pinmode INPUT
		case 1: //pinmode output
		case 2: //digitalWrite(LOW)
		case 3: //digitalWrite(HIGH)
		case 4: //digitalRead
			//printf("digitalRead(%d) sez %d\n",parameter,result);
		case 5: //
		case 6: // setup()
			result=wiringPiSetup ();
			if (result!=0)
 				printf("wiringMVS Setup() sez %d\n",result);
		case 7: // mcp3002Setup()
			result=ads1115Setup (MY_PIN_BASE,0x48);
			if (result0x7ff0) result-=0x10000;
	//printf("wiringMVS sez %d\n",result);
	return result;

Oh, also, I’m normally an SVN user on windows but i decided to try git for tracking changes to the olduino/370 components. For the ads1015c test module it was as simple as
git init
git add ads1015.c
git commit ads1015.c
This is not very sophisticated source code management but it saves me keeping multiple copies of my work for backing off.

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: