User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Programming in Basic on Bare Metal Tutorial 3

Tue Jul 31, 2012 8:56 pm

I have uploaded a new tutorial (3) using DexBasic in bare metal on the Pi.
http://www.dex-os.com/DexBasic/Lesson3.htm

This tutorial is on using the GPIO's.
I will update the language part of the site tomorrow with the new functions.

Note: I have implement the functions to be the same as the equivalent Arduino commands, so anyone who as programmed the arduino or tut available for the arduino, will be easy to convert.
Batteries not included, Some assembly required.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Programming in Basic on Bare Metal Tutorial 3

Wed Aug 01, 2012 5:30 am

I got the tutorial working - for some reason I had to unplug my stepper motor driver board from the GPIO before the LED would flash.

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: Programming in Basic on Bare Metal Tutorial 3

Wed Aug 01, 2012 3:40 pm

pygmy_giant wrote:I got the tutorial working - for some reason I had to unplug my stepper motor driver board from the GPIO before the LED would flash.
Can you give me more info on your "stepper motor driver board" eg: what GPIO is it connected to and what is the layout of that board.
Also the led flash on bootup in the latest boot loader, when you boot any kernel.img, do you normaly see it flash twice with your "stepper motor driver board" connected ?, when you load other kernel.img ?.
Batteries not included, Some assembly required.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Programming in Basic on Bare Metal Tutorial 3

Wed Aug 01, 2012 4:15 pm

One of these: http://www.ebay.co.uk/itm/5V-Stepper-Mo ... 2ebb662977

I tried adapting your tutorial program to drive the stepper - but it would not play.

I have had success driving it via this code in the past (see comments at top of code for connection details):

Code: Select all

// stepping.c
// stepper motor control demonstration for the Raspberry Pi computer
// tested using 28BYJ-48 stepper motor driven via a ULN2003 chip
// powered via 5v and gnd GPIO pins
// uses the GPIO library bcm2835.h provided by Mike McCauley at http://www.open.com.au/mikem/bcm2835/index.html
// compile and execute with
// gcc -o stepping stepping.c -l bcm2835
// chmod +x stepping
// ./stepping
// whilst in the relevant directory
// the sudo keyword may have to be used where appropriate depending on your access privilages and distro

#include <bcm2835.h>

// uses pins 11, 12, 13, 15 (coords a6, b6, a7, a8 on header if in top right corner of board)
#define PIN1 RPI_GPIO_P1_11
#define PIN2 RPI_GPIO_P1_12
#define PIN3 RPI_GPIO_P1_13
#define PIN4 RPI_GPIO_P1_15

int main(int argc, char **argv)
{

// bcm2835_set_debug(1); disables access to pins for debugging
if (!bcm2835_init()) return 1;

// Set the pins to be outputs
bcm2835_gpio_fsel(PIN1, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN2, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN3, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN4, BCM2835_GPIO_FSEL_OUTP);

//use function to move stepper motor as desired
step_motor(12,400,1);
step_motor(48,200,0);

return 1;
}


int step_motor (int step_delay , int steps , int cw)
{
   
step_delay/=4;
if (step_delay<3) step_delay=3;

//clockwise rotation by switching coils in succession for each step
while (steps-- && cw==1)
{

bcm2835_gpio_write(PIN1,HIGH);
bcm2835_gpio_write(PIN4,LOW);
delay(step_delay);

bcm2835_gpio_write(PIN2,HIGH);
bcm2835_gpio_write(PIN1,LOW);
delay(step_delay);

bcm2835_gpio_write(PIN3,HIGH);
bcm2835_gpio_write(PIN2,LOW);
delay(step_delay);

bcm2835_gpio_write(PIN4,HIGH);
bcm2835_gpio_write(PIN3,LOW);
delay(step_delay);

}

//anti clockwise rotation by switching coils in succession in reverse order
while (steps-- && cw==0)
{

bcm2835_gpio_write(PIN4,HIGH);
bcm2835_gpio_write(PIN1,LOW);
delay(step_delay);

bcm2835_gpio_write(PIN3,HIGH);
bcm2835_gpio_write(PIN4,LOW);
delay(step_delay);

bcm2835_gpio_write(PIN2,HIGH);
bcm2835_gpio_write(PIN3,LOW);
delay(step_delay);

bcm2835_gpio_write(PIN1,HIGH);
bcm2835_gpio_write(PIN2,LOW);
delay(step_delay);

}

//set last pin back to low
bcm2835_gpio_write(PIN4,LOW);
bcm2835_gpio_write(PIN1,LOW);

return 0;
}

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: Programming in Basic on Bare Metal Tutorial 3

Wed Aug 01, 2012 4:44 pm

I can convert that code to DexBasic for you to test, but you need to post what pins you are connecting too.
So we know theres not miss understand there.
Can you mark on this image you connections
http://elinux.org/images/2/2a/GPIOs.png
or do something like
A B
C D
E F
G H
I J
K L
M N
O P
Q R
S T
U V
W X
Y Z

Then you can say
A = pin ?
C = pin ?
Just so we are sure we are on the same path as far as pin numbers go.
Also how are you get around the 5v problem, as that board needs 5v.
Batteries not included, Some assembly required.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Programming in Basic on Bare Metal Tutorial 3

Wed Aug 01, 2012 4:59 pm

Appreciated

Having the stepper connected does not affect the behaviour of tut1 or the ok led when it is running.

The DexBasic code I concocted was:

Code: Select all

include 'DexBasic\DexBasic.inc'

pinMode  GPIO17, OUTPUT
pinMode  GPIO18, OUTPUT
pinMode  GPIO21, OUTPUT
pinMode  GPIO22, OUTPUT

LetsLoop:

digitalWrite  GPIO17, HIGH
digitalWrite  GPIO22, LOW
delayMicroseconds  1000000

digitalWrite  GPIO18, HIGH
digitalWrite  GPIO17, LOW
delayMicroseconds  1000000

digitalWrite  GPIO21, HIGH
digitalWrite  GPIO18, LOW
delayMicroseconds  1000000

digitalWrite  GPIO22, HIGH
digitalWrite  GPIO21, LOW
delayMicroseconds  1000000

goto  LetsLoop

align 4
ProgramSize:
ScreenBuffer: 


looking from above and referencing http://elinux.org/images/2/2a/GPIOs.png the pins used are:

O X (+5v)
O O
O X (gnd)
O O
O O
X X (GPIO 17, GPIO 18)
X O (GPIO 21)
X O (GPIO 22)
O O
O O
O O
O O
O O

5v is no problem - I just suck it out throught the top right GPIO pin

Thanks again in advance

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: Programming in Basic on Bare Metal Tutorial 3

Wed Aug 01, 2012 6:08 pm

Thanks for the info, i will take a look at it and i have ordered one of those motors and Module Board ULN2003.
So if we can not get it work in the mean time, i should be able to when it arrives.
Batteries not included, Some assembly required.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Programming in Basic on Bare Metal Tutorial 3

Wed Aug 01, 2012 8:28 pm

Thanks.

God bless the Chinese - I always feel a little bit criminal when I buy something like that so cheaply.

Got my Pi running off lipos:

Image

Am working on a non-kernal space I2C driver using code I nicked from someone else:

Code: Select all

// Annotated userspace I2C driver for the Raspberry Pi computer written in C
// based on code wot I nicked from someone else


// ---------------------------------------------------------------------------------------------------------------------------


#include <stdio.h> // needed to write to the screen
#include <time.h> // needed to read from system clock/callendar
#include <fcntl.h> // contains constructs for file control operations
#include <sys/mman.h> // contains constructs for memory management


#define PAGESIZE 4096 // definition of memory page size
#define BLOCK_SIZE 4096 // definition of memory block size
#define IOBASE   0x20000000 // periferal input/output address
#define BSC0_BASE (IOBASE + 0x205000) // Boardcom Serial Controller #0 (BSC0) address
#define GPIO_BASE (IOBASE + 0x200000) // General Purpose Input/Output (GPIO) address


// http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka3750.html
// example of direct accessing of memory
// #define PORTBASE 0x40000000
// unsigned int volatile * const port = (unsigned int *) PORTBASE;
// *port = value; /* write to port */
// value = *port; /* read from port */


// data structure linked to memory addresses via pointers
struct bcm2835_peripheral {
    unsigned long addr_p; // memory address that accepts value when instance created
    int mem_fd; // file descriptor to physical memory's virtual file '/dev/mem'
    void *map; // pointer to memory map
    volatile unsigned int *addr; // declared as 'volatile' to prevent removal during compiler optomisation as references memory address
};
struct bcm2835_peripheral gpio = {GPIO_BASE}; // structure instance relating to GPIO - addr_p initialised with GPIO_BASE
struct bcm2835_peripheral bsc0 = {BSC0_BASE}; // structure instance relating to BSC0 - addr_p initialised with BSCO_BASE


// The following parameters relate to registers in the Boardcom Serial Controller #0 (BSC0) - they are pointers to the BSC0 address plus an offset relating to a specific register
#define BSC0_C        *(bsc0.addr + 0x00) //Control register address
#define BSC0_S        *(bsc0.addr + 0x01) //Status register address
#define BSC0_DLEN    *(bsc0.addr + 0x02) //Data length register address
#define BSC0_A        *(bsc0.addr + 0x03) //Slave register register address
#define BSC0_FIFO    *(bsc0.addr + 0x04) //First In First Out buffer address


// The following parameters relate to specific bits of the Control Register
// These are set via bitwise left shifting of the value 1 via the logical operator <<
#define BSC_C_I2CEN    (1 << 15) // enables BSC operations - 0 prevents transfers but register accesses is still permitted
#define BSC_C_INTR    (1 << 10) // enable/Disable interrupt on RX - 0 prevents interrupts on RXR condition - 1 generates an interrupt while RXR = 1
#define BSC_C_INTT    (1 << 9) // writing a 0 disables interrupts on TXW - 1 enables; TXW indicates whether the FIFO is full and ready for transfer/reading
#define BSC_C_INTD    (1 << 8) // 1 enables interrupts to alter the DONE condition on completion of a transfer (0 disables). The interrupt remains active until the DONE condition is cleared by writing a 1 to the I2CS.DONE field.
#define BSC_C_ST    (1 << 7) // starts a new data transfer - writing to this field is a one-shot operation (it always reads as zero)
#define BSC_C_CLEAR    (1 << 4) // clears the FIFO - writing to this field is a one-shot operation (it always reads as zero)
#define BSC_C_READ    1 // specifies transfer type as read


// The logical OR opporator, | , is used here to combine the bits above into commands for the control register
#define START_READ    BSC_C_I2CEN|BSC_C_ST|BSC_C_CLEAR|BSC_C_READ // Initialisation of the control register before reading
#define START_WRITE    BSC_C_I2CEN|BSC_C_ST // Initialisation of the control register before writing


// The following parameters relate to specific bits of the Status Register
// These indicate the status of the First In First Out (FIFO) buffer and current data transfer in general
// These are again set via bitwise left shifting of the value 1 via the logical operator <<
#define BSC_S_CLKT    (1 << 9) // is set to indicate that the slave is holding the SCL signal high for an extended time period (clock stretching) - reset by writing a 1 (writing a 0 to the field has no effect)
#define BSC_S_ERR    (1 << 8) // is set to indicate that the slave has failed to acknowledge either its address or a data byte written to it - reset by writing a 1 (writing a 0 to the field has no effect)
#define BSC_S_RXF    (1 << 7) // is set to indicate that the FIFO is full
#define BSC_S_TXE    (1 << 6) // is set to indicate that the FIFO is empty
#define BSC_S_RXD    (1 << 5) // is set to indicate that the FIFO contains at least one byte of data
#define BSC_S_TXD    (1 << 4) // is set to indicate that the FIFO has space for at least one more byte of data
#define BSC_S_RXR    (1 << 3) // generate interrupt to read data from the FIFO before it becomes full
#define BSC_S_TXW    (1 << 2) // generate an interrupt to write more data to the FIFO to complete the current transfer
#define BSC_S_DONE    (1 << 1) // is set to indicate that the transfer has completed
#define BSC_S_TA    1 // is set to indicate the activity of the BSC (1 when busy, 0 when idle)


// The logical OR opporator | is used here to combine the bits above into command to clear the status register
#define CLEAR_STATUS    BSC_S_CLKT|BSC_S_ERR|BSC_S_DONE // reset/initialise ready for fresh transfer


// forward declarations
void dump_bsc_status();
int map_peripheral(struct bcm2835_peripheral *p);
void unmap_peripheral(struct bcm2835_peripheral *p);


int map_peripheral(struct bcm2835_peripheral *p) // Exposes the physical address defined in the passed structure using mmap on /dev/mem
{
   // Open /dev/mem
   if ((p->mem_fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0) {
      printf("Failed to open /dev/mem, try checking permissions.\n");
      return -1;
   }

   p->map = mmap(
      NULL,
      BLOCK_SIZE,
      PROT_READ|PROT_WRITE,
      MAP_SHARED,
      p->mem_fd,  // File descriptor to physical memory virtual file '/dev/mem'
      p->addr_p      // Address in physical map that we want this memory block to expose
   );

   if (p->map == MAP_FAILED) {
        perror("mmap");
        return -1;
   }

   p->addr = (volatile unsigned int *)p->map;

   return 0;
}


void unmap_peripheral(struct bcm2835_peripheral *p) // removes virtual memory map
{
    munmap(p->map, BLOCK_SIZE);
    close(p->mem_fd);
}


void dump_bsc_status() // prints status register settings to the screen
{
    unsigned int s = BSC0_S;
    printf("BSC0_S: ERR=%d  RXF=%d  TXE=%d  RXD=%d  TXD=%d  RXR=%d  TXW=%d  DONE=%d  TA=%d\n",
        (s & BSC_S_ERR) != 0,
        (s & BSC_S_RXF) != 0,
        (s & BSC_S_TXE) != 0,
        (s & BSC_S_RXD) != 0,
        (s & BSC_S_TXD) != 0,
        (s & BSC_S_RXR) != 0,
        (s & BSC_S_TXW) != 0,
        (s & BSC_S_DONE) != 0,
        (s & BSC_S_TA) != 0 );
}


void wait_i2c_done() // Function to wait for the I2C transaction to complete
{
        //Wait till done, let's use a timeout just in case
        int timeout = 50; // 50ms timeout value
        while((!((BSC0_S) & BSC_S_DONE)) && --timeout) {
            usleep(1000); // sleep for 1ms while BSC acts
        }
        if(timeout == 0)
            printf("I2C transfer timeout - something went wrong.\n");
}


// Binary Coded Decimal (BCD) helper functions - only apply to BCD 0-99 (one byte) values
unsigned int bcdtod(unsigned int bcd)
{
    return ((bcd & 0xf0) >> 4) * 10 + (bcd & 0x0f);
}

unsigned int dtobcd(unsigned int d)
{
    return ((d / 10) << 4) + (d % 10);
}


// EXAMPLE IMPLMENTATION STARTS HERE ---------------------------------------------------------------------------------------------------------------------------


int main(int argc, char *argv[])
{

    if(map_peripheral(&gpio) == -1) {
        printf("Failed to map the physical GPIO registers into the virtual memory space.\n");
        return -1;
    }
	
    if(map_peripheral(&bsc0) == -1) {
        printf("Failed to map the physical BSC0 (I2C) registers into the virtual memory space.\n");
        return -1;
    }

	
// ?? BSC0 is on GPIO 0 & 1
    *gpio.addr &= ~0x3f; // use & logic operator to set bits 0-5 of function select (FSEL0) to zero
    *gpio.addr |= 0x24;  // use | logic operator to set bits 0-5 of function select (FSEL0) to binary '100100'

	
// WRITE SEQUENCE TEMPLATE BELOW ---------------------------------------------------------------------------------------------------------------------------
	

    BSC0_A = 0x51; // example - replace with real slave address
	
        BSC0_DLEN = 16; // example - replace with real data length
        BSC0_FIFO = 0x0; // example - replace 0x0 with real data (number of FIFO write instances below must relate to DLEN above)
        BSC0_FIFO = 0x0;
		BSC0_FIFO = 0x0;
        BSC0_FIFO = 0x0;
        BSC0_FIFO = 0x0;
        BSC0_FIFO = 0x0;
        BSC0_FIFO = 0x0;
        BSC0_FIFO = 0x0;
        BSC0_FIFO = 0x0;
        BSC0_FIFO = 0x0;
        BSC0_FIFO = 0x0;
        BSC0_FIFO = 0x0;
        BSC0_FIFO = 0x0;
        BSC0_FIFO = 0x0;
        BSC0_FIFO = 0x0;
        BSC0_FIFO = 0x0;		

        BSC0_S = CLEAR_STATUS; // reset status register
        BSC0_C = START_WRITE; // initiate writing
        wait_i2c_done(); // wait for data transaction to complete (or fail) 


// READ SEQUENCE TEMPLATE BELOW ---------------------------------------------------------------------------------------------------------------------------

    BSC0_DLEN = 7; // example - replace with number of bytes to read - relates to number of read values shown below
    BSC0_S = CLEAR_STATUS; // reset status register
    BSC0_C = START_READ; // initiate reading
    wait_i2c_done(); // wait for data transaction to complete (or fail)

    // example - display read values, after masking unimplemented bits via logical & operator (replace mask of 0x7f with correct value - if any)
    printf("%d \n",bcdtod(BSC0_FIFO & 0x7f));
	printf("%d \n",bcdtod(BSC0_FIFO & 0x7f));
	printf("%d \n",bcdtod(BSC0_FIFO & 0x7f));
	printf("%d \n",bcdtod(BSC0_FIFO & 0x7f));
	printf("%d \n",bcdtod(BSC0_FIFO & 0x7f));
	printf("%d \n",bcdtod(BSC0_FIFO & 0x7f));
	printf("%d \n",bcdtod(BSC0_FIFO & 0x7f));
    }

	
	// remove virtual memory map
    unmap_peripheral(&gpio);
    unmap_peripheral(&bsc0);

	
}

Its quite linear - so maybe it could easily convert to dexbasic?

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: Programming in Basic on Bare Metal Tutorial 3

Wed Aug 01, 2012 9:06 pm

Cool :) .

From a bit of reading, i put together this test code, from some arduino code i found, it just rotates in one direction.

Code: Select all

include 'DexBasic\DexBasic.inc'                    
                                                   ;
motorPin1 = GPIO17                                 ; Blue   - 28BYJ48 pin 1
motorPin2 = GPIO18                                 ; Pink   - 28BYJ48 pin 2
motorPin3 = GPIO21                                 ; Yellow - 28BYJ48 pin 3
motorPin4 = GPIO22                                 ; Orange - 28BYJ48 pin 4
                                                   ;
pinMode  GPIO17, OUTPUT                            ;
pinMode  GPIO18, OUTPUT                            ;
pinMode  GPIO21, OUTPUT                            ;
pinMode  GPIO22, OUTPUT                            ;
                                                   ;
LetsLoop:                                          ; a label
  digitalWrite motorPin4, HIGH                     ;
  digitalWrite motorPin3, LOW                      ;
  digitalWrite motorPin2, LOW                      ;
  digitalWrite motorPin1, LOW                      ;
  delayMicroseconds 22000                          ;
                                                   ;
  digitalWrite motorPin4, HIGH                     ;
  digitalWrite motorPin3, HIGH                     ;
  digitalWrite motorPin2, LOW                      ;
  digitalWrite motorPin1, LOW                      ;
  delayMicroseconds 22000                          ;
                                                   ;
  digitalWrite motorPin4, LOW                      ;
  digitalWrite motorPin3, HIGH                     ;
  digitalWrite motorPin2, LOW                      ;
  digitalWrite motorPin1, LOW                      ;
  delayMicroseconds 22000                          ;
                                                   ;
  digitalWrite motorPin4, LOW                      ;
  digitalWrite motorPin3, HIGH                     ;
  digitalWrite motorPin2, HIGH                     ;
  digitalWrite motorPin1, LOW                      ;
  delayMicroseconds 22000                          ;
                                                   ;
  digitalWrite motorPin4, LOW                      ;
  digitalWrite motorPin3, LOW                      ;
  digitalWrite motorPin2, HIGH                     ;
  digitalWrite motorPin1, LOW                      ;
  delayMicroseconds 22000                          ;
                                                   ;
  digitalWrite motorPin4, LOW                      ;
  digitalWrite motorPin3, LOW                      ;
  digitalWrite motorPin2, HIGH                     ;
  digitalWrite motorPin1, HIGH                     ;
  delayMicroseconds 22000                          ;
                                                   ;
  digitalWrite motorPin4, LOW                      ;
  digitalWrite motorPin3, LOW                      ;
  digitalWrite motorPin2, LOW                      ;
  digitalWrite motorPin1, HIGH                     ;
  delayMicroseconds 22000                          ;
                                                   ;
  digitalWrite motorPin4, HIGH                     ;
  digitalWrite motorPin3, LOW                      ;
  digitalWrite motorPin2, LOW                      ;
  digitalWrite motorPin1, HIGH                     ;
  delayMicroseconds 22000                          ;
                                                   ;
goto  LetsLoop                                    
                                                   ;
align 4                                           
ProgramSize:                                     
ScreenBuffer:                                     
Note: the wire colors to gpio, your maybe wire differently, so may need moding.
Batteries not included, Some assembly required.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Programming in Basic on Bare Metal Tutorial 3

Wed Aug 01, 2012 9:12 pm

cheers mate - will give it a go tomorrow ...


User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: Programming in Basic on Bare Metal Tutorial 3

Thu Aug 02, 2012 6:38 pm

Could you post how you are wiring the motor and module board to the PI.
And how you are powering the motor.
Thanks.
Batteries not included, Some assembly required.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Programming in Basic on Bare Metal Tutorial 3

Thu Aug 02, 2012 6:45 pm

looking from above and referencing http://elinux.org/images/2/2a/GPIOs.png the pins used are:

O X (+5v out of pi to supply pin of stepper motor board)
O O
O X (gnd to gnd pin on stepper motor board)
O O
O O
X X (GPIO 17, GPIO 18 to 1st and 2nd input pins of stepper motor controller board respectively)
X O (GPIO 21 to 3rd input pin of stepper motor controller board)
X O (GPIO 22 to 4th input pin of stepper motor controller board)
O O
O O
O O
O O
O O

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: Programming in Basic on Bare Metal Tutorial 3

Thu Aug 02, 2012 7:32 pm

Thanks.
Batteries not included, Some assembly required.

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: Programming in Basic on Bare Metal Tutorial 3

Thu Aug 02, 2012 10:39 pm

Its seem i uploaded the wrong tut3 file, no-wonder it did not work, i will post the right one latter.
Batteries not included, Some assembly required.

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: Programming in Basic on Bare Metal Tutorial 3

Fri Aug 03, 2012 5:12 pm

@pygmy_giant , here's the fixed code, but you must use the new boot loaders files and config.txt ( the onces in the boot folder ) on your sd card, as they seem to of change some stuff around.
http://www.dex-os.com/DexBasic/ULN2003.zip

Note: To anyone that test DexBasic, make sure you use the loader files that are in the zip, to replace the once you have on your sd card, as they are the latest once.
Batteries not included, Some assembly required.


User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: Programming in Basic on Bare Metal Tutorial 3

Mon Aug 06, 2012 5:16 pm

pygmy_giant wrote:works a treat :D
Cool and thanks for testing :) .
Batteries not included, Some assembly required.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Programming in Basic on Bare Metal Tutorial 3

Wed Aug 08, 2012 5:24 pm

I speeded it up: http://www.nsd.uk.com/miscellaneous/MVI_2584.AVI

I think this is the first example of Bare Metal automotive control on th Pi.

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: Programming in Basic on Bare Metal Tutorial 3

Wed Aug 08, 2012 6:11 pm

pygmy_giant wrote:I speeded it up: http://www.nsd.uk.com/miscellaneous/MVI_2584.AVI

I think this is the first example of Bare Metal automotive control on th Pi.
Cool and i think you could be right about the above, my controller and motor arrived today will give it a test and add reverse to the code.
I will post it here's.

Note: this method of using 8 pulse, gives the motor more torque.
Batteries not included, Some assembly required.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Programming in Basic on Bare Metal Tutorial 3

Wed Aug 08, 2012 7:16 pm

Fab.

There is also a lot of talk about the need for precise timing of GPIO inputs and some of how this in conjunction with a capacitor alongside a resistive sensor could provide a work-around for the lack of analogue input - that could be another first!

I would like to do something similar with my experimental capacative sensing circuit:

Image

( http://www.raspberrypi.org/phpBB3/viewt ... in#p139918 )

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: Programming in Basic on Bare Metal Tutorial 3

Wed Aug 08, 2012 7:49 pm

I will take a look, just tested mine, got a bit of a shock at first, as the led were red, but it seem some have red leds.
Not as fast as i thought, i get fastest speed at 1000 any smaller timing and the motor just buzzs.
I will try some different pulse combos.

Ps: I know they are geared down and that's fine, but the method use here is supposed to be twice as fast, if needed and more torque.
It does have lots of torque.
Batteries not included, Some assembly required.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Programming in Basic on Bare Metal Tutorial 3

Wed Aug 08, 2012 7:56 pm

yeah - it is quite slow, but what can you expect from a £3 stepper - I set my delay to 2000.

the controller board is possibly mor use than the motor - you can pick these up for £1.50 !

If you had 2 or 3 and a bunch of solenoids you could re-create Grumpy Mike's Gockenspeil project: http://www.raspberrypi.org/archives/1471

boz
Posts: 2
Joined: Thu Aug 09, 2012 12:33 am

Re: Programming in Basic on Bare Metal Tutorial 3

Thu Aug 09, 2012 2:34 am

Dex - Thanks for the work your doing on this.

The term DexBasic got me a bit worried at first as I'm a bit of a low-level microcontroller coder and havent done basic since the ZX81, but now I've seen its just a bunch of smart macros covering assembly language, the tutorials were magic (except tut2 where I didnt get any serial output - I may revisit it sometime) and Macro assembly seems ideal way to get me up to speed quickly while my ARM assembly skills improve !

My ultimate goal is a recreational project to convert an old Atari ST arcade game I wrote back in the 80's but never finished, this had a lot of machine code routines, around the sprite manipulation, and I still have a lot of the notes which I'm looking forward to starting in a few months, having it instant-on is a major criteria for going bare-metal as its going in an old style arcade box

Hopefully once I'm pointed in the right direction with the graphics controller I will give it a go. two things would be nice:

1. if anyone comes up with some nice graphics/sprite assembly routines in the mean time and they could make them available that would be great.

2. The Compile -> write to SD -> boot Pi cycle is a bit slow, I may play with it on the emulator see if it speeds it up

Keep up the good work.

User avatar
Cycl0ne
Posts: 102
Joined: Mon Jun 25, 2012 8:03 am

Re: Programming in Basic on Bare Metal Tutorial 3

Thu Aug 09, 2012 9:07 am

2) use the bootloader from dwelch -> gets you faster to your goal.
Open up a terminal,
power on raspberry
send with terminal your prg to raspberry
have fun

Return to “Bare metal, Assembly language”