Dumbot Revision 2 by hmikelson 3d model
Warning. This content is not moderated and could be offensive.
m4
3dmdb logo
Thingiverse
Dumbot Revision 2 by hmikelson

Dumbot Revision 2 by hmikelson

by Thingiverse
Last crawled date: 2 years, 11 months ago
You need two hubs and two of each kind of wheel. I use 30 mm x 40 mm x 5 mm O-rings available from Amazon. You need 4 M3 x 25 mm screws to hold the motors on and 2 x 8-32 3/4" screws for one set of wheels. You need two motors available from Spark fun (hobby motors 2 for $5), You need a brushed motor controller from Sparkfun with headers $5, you need a 3xAA battery pack with switch available from Jameco, and a PIR motion sensor available from Amazon. The code is for a PIC16F1825 microcontroller. I also use a PCB speaker from parts express along with a 386 audio amplifier (and supporting circuitry) and an LED from Lighthouse LEDs. In the code the motor pulse frequency changes so I route an output pin to the speaker so as the robot goes faster the pitch gets louder. You can use velcro to hold stuff down, since I make my own PCBs I use the PCB holders.
https://www.youtube.com/watch?v=ioGz1LwgC6o
Looks like some of the includes in the code confuses the html processor.
/*
File: R06Main.c
Author: hmikelson


Created on September 4, 2018, 6:11 PM
*/
include
include
include
pragma config MCLRE=OFF,CP=OFF,WDTE=OFF,FOSC=INTOSC
define _XTAL_FREQ 16000000
unsigned char sPORTA, sPORTC, pwmax=31;
void init()
{
//Configure GPIO Port
TRISA = 0b110000000; //Set all Output
TRISC = 0b110001000; //Set up pin 3 for input
OSCCONbits.IRCF = 0b1111;
OSCCONbits.SCS = 0b00;
//OPTION_REG = 0b01111111; //Global enable weak pullups
//WPUC = 0b00001000; //Enable weak pullups with a 1
// Set up analog input
ANSELCbits.ANSC3 = 1;
ADCON0 = 0b00011101; //Channel (CHS4:0 bits 6-2),ADON bit 1 enable Analog
ADCON1bits.ADCS = 0b111; // clock select dedicated osc
ADCON1bits.ADNREF = 0; //neg ref
ADCON1bits.ADPREF = 0; //config + voltage with vdd
ADCON1bits.ADFM = 1; //format left justified
ADRESH = 0x00; //Init the AD Register
ADRESL = 0x00; // I don't think this is needed
//OSCCONbits.SPLLEN = 0b1;
}
void vdelay(int n)
{
int i;
for (i=0;i<=n;i++)
{
__delay_us(100);
}
}
int read_v()
// Read voltage from input
{
int val,v1,v2;
__delay_ms(1);
ADCON0bits.GO_nDONE = 1;
while(ADCON0bits.GO_nDONE == 1);
v1 = ADRESH;
v2 = ADRESL;
val = (v1<<8) + v2;
return val;
}
// Drive robot forward
void RobotFd(int time, unsigned char speed)
{
int i, j;
for (i=0;i{
for (j=0;j{
if (j{
PORTA = 0b00111110; //
PORTC = 0b00010110; // Enable on pin 4
vdelay(pwmax/speed);
}
else
{
PORTA = 0b00000110; // I think there is a clock output on pin 4 which I don't know how to disable
PORTC = 0b00010010; // Enable on pin 4
vdelay(pwmax/speed);
}
}

}
}
// Drive Robot backward
void RobotBk(int time, unsigned char speed)
{
int i, j;
for (i=0;i{
for (j=0;j{
if (j{
PORTA = 0b00111101;
PORTC = 0b00010101;
vdelay(pwmax/speed);
}
else
{
PORTA = 0b00000101;
PORTC = 0b00010001;
vdelay(pwmax/speed);
}
}

}
}
void RobotRt(int time, unsigned char speed)
{
int i, j;
for (i=0;i{
for (j=0;j{
if (j{
PORTA = 0b00111110;
PORTC = 0b00010101;
vdelay(pwmax/speed);
}
else
{
PORTA = 0b00000110;
PORTC = 0b00001001;
vdelay(pwmax/speed);
}
}

}
}
void RobotLt(int time, unsigned char speed)
{
int i, j;
for (i=0;i{
for (j=0;j{
if (j{
PORTA = 0b00111101;
PORTC = 0b00110110;
vdelay(pwmax/speed);
}
else
{
PORTA = 0b00000101;
PORTC = 0b00001010;
vdelay(pwmax/speed);
}
}

}
}
void RobotSt(int time)
{
int i;
for (i=0;i{
PORTA = 0b00000100;
PORTC = 0b00001100;
__delay_ms(10);
}
}
void main()
{
int rmode, rtime, volts,mt=31;
unsigned char rspeed, nactions=0;
init();
RobotFd(100,pwmax/2);
RobotSt(1);
RobotRt(100,pwmax/2);
RobotSt(1);
RobotBk(100,pwmax/2);
RobotSt(1);
RobotLt(100,pwmax/2);
RobotSt(1);
while(1)
{
if (nactions > 0)
{
rmode=(rand() & 7) + 1;
nactions=nactions-1;
}
else
{
rmode = 0;
}
rtime = (rand() & 7)+1;
rspeed = rand() & pwmax;
switch (rmode)
{
case 1:
RobotFd(rtimemt,rspeed);
RobotSt(1);
break;
case 2:
RobotBk(rtimemt,rspeed);
RobotSt(1);
break;
case 3:
RobotRt(rtimemt,rspeed);
RobotSt(1);
break;
case 4:
RobotLt(rtimemt,rspeed);
RobotSt(1);
break;
case 0:
RobotSt(1);
volts = read_v();
if (volts>50)
{
nactions = 10;
//blink(volts);
}
break;
default:
RobotSt(10);
break;
}
}
}

Tags