Help translate Picaxe to Arduino

I need to translate the following code Picaxe to Arduino to do a library on GLCD 192x64 KS0108B and I2C controller Bv4613 of Byvac.

The code is this:

pause 1000
Main:
Hi2csetup i2cmaster,0x64,i2cslow,i2cbyte
pause 1000
HI2cOut ("Before CLS")
pause 1000

'Clear screen
HI2cOut ($1b) ; esc
HI2cOut ($5b) ; [
HI2cOut ($32) ; 2
HI2cOut ($4a) ; J
Pause 1000

HI2cOut ($1b,$5b,$3f,$32,$35,$49) 'Hide cursor
pause 20

HI2cOut ("After CLS")
pause 1000

'Move cursor
'HI2cOut ($1b,$5b,$32,$3b,$31,$35,$48) can use hex or ascii code
HI2cOut ( 27 ,91 ,50 ,59 ,49, 53,72)
pause 1000

HI2cOut ("After move 2-15")
pause 1000

HI2cOut (CR)
pause 1000

b1=$2a
HI2cOut ("b1 is an asterisk ",b1) ;Write value of variable b1
pause 1000

'Draw rectangle
'Coords (esc { 3 2 , 3 6 , 1 1 1 , 4 5 R)
'HI2cOut ($1b,$7b,$33,$32,$2c,$33,$36,$2c,$31,$31,$31,$2c,$34,$35,$46)
HI2cOut ( 27,123, 51, 50, 44, 51, 54, 44, 49, 49, 49, 44, 52, 53, 82)
Pause 1000

'Draw filled rectangle
HI2cOut ( 27,123, 51, 53, 44, 51, 57, 44, 49, 48, 56, 44, 52, 51, 70)
pause 1000

HI2cOut (CR)
pause 20

HI2cOut ($1b,$5b,$49) 'invert colours
pause 20

HI2cOut (" thats all folks!! ")
Pause 20

HI2cOut ($1b,$5b,$49) 'un-invert colours
pause 20

You need to start with checking the Wire library for the I2C calls.- Wire - Arduino Reference -

some starters:

pause 1000 => delay(1000);

hex numbers are written with 0x prefix $1b -> 0x1B
comment is // iso ; and '

the commands can be made into an array that are written to Wire object this way

uint8_t CLS[] = { 0x1B, 0x5B, 0x32, 0x4A };
uint8_t HC[] = { 0x1b, 0x5b, 0x3f, 0x32, 0x35, 0x49 };

void clearScreen()
{
  Wire.beginTransmission(44);
  Wire.write(CLS, 6);
  Wire.endTransmission();
}

void hideCursor()
{
  Wire.beginTransmission(44);
  Wire.write(HC, 6);
  Wire.endTransmission();
}

void printString(char * s)
{
  Wire.beginTransmission(44);
  Wire.write(s);
  Wire.endTransmission();
}

should get you started

Another convert from Picaxe, maybe someone should write a tutorial. I nominate you Rob :), you've made a good start.


Rob

or a picaxe interpreter ...

Ah, now that's not a bad idea, after all that's all the Picaxe does. But you would really need to have the format of their "p-code" and I'm sure they don't release that.

On a larger Arduino you could run a full interpreter and download the source code though.

On second thoughts just learn C.


Rob

Now I understand the syntax, I can already clear screen.

But the example to position cursor, draw rectangles, etc. are too many commands to run on the controller BV4613, the worst is that I can not find any document explaining the supported commands and their syntax.

'Draw filled rectangle
HI2cOut ( 27,123, 51, 53, 44, 51, 57, 44, 49, 48, 56, 44, 52, 51, 70)
pause 1000

==>

uint8_t rect[] = { 27,123, 51, 53, 44, 51, 57, 44, 49, 48, 56, 44, 52, 51, 70 };

void setup()
{
   //...

   drawArray(rect, sizeof(rect)/sizeof(rect[0]));
}
...

void drawArray( uint8_t  *ar,  uint8_t len)  // the * denotes a pointer , in this case to the address of an array ..
{
  Wire.beginTransmission(44);
  Wire.write(ar, len);
  Wire.endTransmission();
}

Ok, but I need know that the array are commands to define the size and position of the rectangle.

is that a question?

maybe drawShape(*ar , len) would be a better name.

I can not get it to work.

post your code, so we can see what fails

#include <Wire.h>
uint8_t rect[] = { 27,123, 51, 53, 44, 51, 57, 44, 49, 48, 56, 44, 52, 51, 70 };

void setup()
{
Wire.begin();
Wire.beginTransmission(0x32);
Wire.write(0x1B);//cls
Wire.write(0x5B);
Wire.write(0x32);
Wire.write(0x4A);
Wire.endTransmission();

Wire.begin();
Wire.beginTransmission(0x32);
Wire.write(0x1B); // esconde cursor
Wire.write(0x5B);
Wire.write(0x3F);
Wire.write(0x32);
Wire.write(0x35);
Wire.write(0x49);
Wire.endTransmission();
}
void drawArray( uint8_t *ar, uint8_t len)
{
Wire.beginTransmission(0x32);
Wire.write(ar, len);
Wire.endTransmission();
}

void loop()
{
drawArray(rect, sizeof(rect)/sizeof(rect[0]));
}

I need a library to use the Arduino lcd 192x64 with KS0108B for Vybac BV4613 I2C controller.
My experience creating libraries is none.
But documentation in the network is very low.

Did the picaxe code work?

ea5elf:
But the example to position cursor, draw rectangles, etc. are too many commands to run on the controller BV4613, the worst is that I can not find any document explaining the supported commands and their syntax.

http://www.byvac.co.uk/downloads/datasheets/BV4613%20DataSheet.pdf page 9 onwards.

For completeness you can fine lots of info here.

Yes but that list of commands is to serial not serve to I2C.

Now I begin to understand the syntax.

I need to correct the void to write text or variables in the ldc.

This example above fails.

void printString(char * s)
{
Wire.beginTransmission(44);
Wire.write(s);
Wire.endTransmission();
}

ea5elf:
Yes but that list of commands is to serial not serve to I2C.

I assume the list of commands are used to control the LCD. It does not matter if they are delivered to it using Serial, Parallel, SPI or I2C the commands would always be the same.

If it is right, and start to make it work.

I need help to implement in the library for the posion of cursor variables, print text, rectangles to send coordinates from skeech to library.

ea5elf:
I need help to implement in the library for the posion of cursor variables, print text, rectangles to send coordinates from skeech to library.

I'm getting confused now.
Do you have the already written arduino library for the BV4613 device you mention in your first post or are you trying to write your own library?
If you using the already written library then what commands are you having problems with? The header file will go a long way to helping you work out what the commands are and how to use them.

Public section extract from BV4613 library.

 public:
  BV4613(void);

  int GET_DHeight() { return 64; };
  int GET_DWidth() { return 192; };

  int GET_COLS() { return 32; };
  int GET_LINS() { return 8; };

  void Init(int Dir);

  void Write_CR();
  void Write_LF();
  void Write_BS();

  void Cursor_POS(int Fila,int Columna);
  void Cursor_UP(int NL);
  void Cursor_DOWN(int NL);
  void Cursor_LEFT(int NC);
  void Cursor_RIGHT(int NC);
  void Cursor_HOME();
  void Cursor_ON();
  void Cursor_OFF();

  void Scroll_ON();
  void Scroll_OFF();

  void BackLight_ON();
  void BackLight_OFF();

  void CursorRate(int Rate);

  void SET_I2CAdress(int Dir);
  int GET_DeviceID();
  int GET_FirmwareVersion();

  void Reset();

  void SET_FontSize(int Size);
  void SET_Inverse();

  void Cls();
  void ClearLineRight();
  void ClearLineLeft();
  void ClearLine();

  void Line(TPointI P1,TPointI P2);
  void Rectangle(TPointI P1,TPointI P2);
  void FRectangle(TPointI P1,TPointI P2);
  void Circle(TPointI P,int R);
  void SetPixel(TPointI P,int Color);
  void SET_CursorPixel(TPointI P);
  TPointI GET_CursorPixel();

  void WriteText(int F,int C,char *,int color=1);
  void WriteText(TPointI C,char *,int color=1);
  void WriteText(char *,int color=1);

  void PaintBitmap(TPointI,::TBitmap *);