Register

fx-9860GII - Arduino - Communication

Discuss anything related to calculators. For specific help on certain games/programs check the Released Projects subforum.
Junior Member
Posts: 14
Joined: Fri Apr 26, 2013 5:57 pm
Location: BW, Germany
Calculators: Casio fx-9860 GII

fx-9860GII - Arduino - Communication

Postby Pedantis » Sun May 19, 2013 11:57 pm

Some time ago, I spoke with Simon Lothar about the use of the serial port integrated in the fx-9860GII for communication purposes. As some of you might know, there is an Add-In available, called Terminal and developed by Kucalc, which provides a possibility for calc-calc-communication via the serial port.
But for some more sophisticated project I need a way to be able to transmit strings from the calculator to an Arduino (a simple microcontroller board) in a different way.
My question is: Is there a way to make an Add-In where you can input some text and transfer it by hitting something like a "OK"-Button via the serial port?
I am familiar with C/C++, but I never developed Add-Ins for the fx-9860GII.
Any kind of help would be greatly appreciated.

Senior Member
Posts: 68
Joined: Sat Feb 02, 2013 4:29 am
Calculators: Casio Cfx Series, Casio fx-CG 10

Re: fx-9860GII - Arduino - Communication

Postby nsg » Mon May 20, 2013 12:30 am

I would like to refer you to this thread about casio com communication.
Nominally it is about Prizm, but I ended up using CFX for actual project.
viewtopic.php?f=22&t=1490

Also, I would like to encourage you to explore all possible ways to stay with Basic until you can.
You need calculator for the user interface (to display numbers received from arduino and send input numbers back to arduino with possibly some text prompts and number scaling/conversion) and in projects like this you will want to tweak it a lot. It is way easier to do in basic even with all its drawbacks. Implement casio alpha send/receive protocol, it is described in detail and just use Basic Send/Receive to exchange numbers.

Here is another video where my buddy uses TI as a display device for arduino-based sensor pack.
http://www.youtube.com/watch?v=IN0oifPyCwA

Senior Member
Posts: 350
Joined: Tue Jan 03, 2012 11:24 pm
Calculators: Casio Afx 1.0, Casio fx-9860 GII SD, Casio Classpad 330, Casio fx-CG 20, Casio Classpad fx-cp400

Re: fx-9860GII - Arduino - Communication

Postby helder7 » Mon May 20, 2013 1:22 am

I'll leave here a small example for serial (for you start)...

You should create a new sdk project. And after you should add the file "Syscalls.src" to the sdk source files.

Sample "Syscalls.src" for serial communication:

Code: Select all
   .SECTION P,CODE,ALIGN=4
   .MACRO SYSCALL FUNO, SYSCALLNAME, TAIL=nop
   .export \SYSCALLNAME'
\SYSCALLNAME'
   mov.l #h'\FUNO, r0
   mov.l #H'80010070, r2
   jmp @r2
   \TAIL'
   .ENDM

   SYSCALL 040C,   _Serial_ReadOneByte
   SYSCALL 040E,   _Serial_BufferedTransmitOneByte
   SYSCALL 0418,   _Serial_Open
   SYSCALL 0419,   _Serial_Close

   .end


back to .c, you should put the functions declaration after the #include:
Code: Select all
int Serial_BufferedTransmitOneByte( unsigned char );
int Serial_Open( void*sm );
int Serial_Close( int mode );
int Serial_ReadOneByte( unsigned char* );


to open the port, you can use something like:

Code: Select all
char mode[6];
mode[ 0 ] = 0;
mode[ 1 ] = 9;//0=300, 1=600, 2=1200, 3=2400, 4=4800, 5=9600, 6=19200, 7=38400, 8=57600, 9=115200 baud
mode[ 2 ] = 2;//parity: 0=no; 1=odd; 2=even
mode[ 3 ] = 0;//datalength: 0=8 bit; 1=7 bit
mode[ 4 ] = 0;//stop bits: 0=one; 1=two
mode[ 5 ] = 0;
Serial_Open(&mode);


Then you can send byte's with Serial_BufferedTransmitOneByte

like:
Code: Select all
unsigned char demo;
demo='F';
Serial_BufferedTransmitOneByte(demo);


you should read the Simon Lothar doc fx_calculators_SuperH_based.chm (17) that exlains the serial syscalls in detail. This is just a quick start exemple based on his document.
SiO2 + CaCO3 ----------> CaSiO3 + CO2

Junior Member
Posts: 14
Joined: Fri Apr 26, 2013 5:57 pm
Location: BW, Germany
Calculators: Casio fx-9860 GII

Re: fx-9860GII - Arduino - Communication

Postby Pedantis » Mon May 20, 2013 11:40 am

Thanks for the nice example, helder7!

It works like a charm.

This is the code I am using:
Code: Select all
#include "fxlib.h"

int Serial_BufferedTransmitOneByte(unsigned char);
int Serial_Open(void*sm);
int Serial_Close(int mode);
int Serial_ReadOneByte(unsigned char*);
unsigned int key;
unsigned char demo;

int AddIn_main(int isAppli, unsigned short OptionNum)
{
    char mode[6];
    mode[0] = 0;
    mode[1] = 5;
    mode[2] = 2;
    mode[3] = 0;
    mode[4] = 0;
    mode[5] = 0;
    Serial_Open(&mode);
    demo='F';
    Serial_BufferedTransmitOneByte(demo);

    Bdisp_AllClr_DDVRAM();
    locate(1,4);
    Print((unsigned char*)"Some");
    locate(1,5);
    Print((unsigned char*)"text");
    while(1){
        GetKey(&key);
    }

    return 1;
}


#pragma section _BR_Size
unsigned long BR_Size;
#pragma section
#pragma section _TOP
int InitializeSystem(int isAppli, unsigned short OptionNum)
{
    return INIT_ADDIN_APPLICATION(isAppli, OptionNum);
}
#pragma section


The only thing I changed is the initialization of the demo-char (it failed during building the file when I tried to initialize it directly before demo='F', I don't know why).
I programmed the Arduino as a simple serial repeater in order to be able to see transmitted text on my computer.

Image
This is the construction I use.

The next step would be to send a string - how can I do that?
Futhermore, I would like to be able to enter a string on the calculator. How can I do that?

Junior Member
Posts: 14
Joined: Fri Apr 26, 2013 5:57 pm
Location: BW, Germany
Calculators: Casio fx-9860 GII

Re: fx-9860GII - Arduino - Communication

Postby Pedantis » Mon May 20, 2013 12:50 pm

UPDATE:
I implemented a new procedure to send a string:
Code: Select all
#include "fxlib.h"
#include "string.h"

int Serial_BufferedTransmitOneByte(unsigned char);
int Serial_Open(void*sm);
int Serial_Close(int mode);
int Serial_ReadOneByte(unsigned char*);
int i;
int j;
unsigned int key;
unsigned char demo;
char test[] = "Lorem ipsum dolor sit amet";

int AddIn_main(int isAppli, unsigned short OptionNum)
{
    char mode[6];
    mode[0] = 0;
    mode[1] = 5;
    mode[2] = 2;
    mode[3] = 0;
    mode[4] = 0;
    mode[5] = 0;
    Serial_Open(&mode);
    for(i=0; i<strlen(test); i++)
    {
        Serial_ClearTransmitBuffer();
        demo=test[i];
        Serial_BufferedTransmitOneByte(demo);
       
        Sleep(100);
        Serial_ClearTransmitBuffer();
        Sleep(100);
    }
    Bdisp_AllClr_DDVRAM();
    locate(1,4);
    Print((unsigned char*)"Some");
    locate(1,5);
    Print((unsigned char*)"text");
    while(1){
        GetKey(&key);
    }

    return 1;
}


#pragma section _BR_Size
unsigned long BR_Size;
#pragma section
#pragma section _TOP
int InitializeSystem(int isAppli, unsigned short OptionNum)
{
    return INIT_ADDIN_APPLICATION(isAppli, OptionNum);
}
#pragma section


For this purpose I added a new syscall in syscalls.src:
Code: Select all
   .SECTION P,CODE,ALIGN=4
   .MACRO SYSCALL FUNO, SYSCALLNAME, TAIL=nop
   .export \SYSCALLNAME'
\SYSCALLNAME'
   mov.l #h'\FUNO, r0
   mov.l #H'80010070, r2
   jmp @r2
   \TAIL'
   .ENDM

   SYSCALL 040C,   _Serial_ReadOneByte
   SYSCALL 040E,   _Serial_BufferedTransmitOneByte
   SYSCALL 0418,   _Serial_Open
   SYSCALL 0419,   _Serial_Close
   SYSCALL 0414,   _Serial_ClearTransmitBuffer

   .end


The sleeps in the .c are for debugging purposes.
Strangely, the resulted output on my computer looks always like this:
"Loÿrÿeÿm iÿpsum doÿlÿoÿrÿ siÿtÿ ameÿtÿ"
Does somebody know why?

Senior Member
Posts: 350
Joined: Tue Jan 03, 2012 11:24 pm
Calculators: Casio Afx 1.0, Casio fx-9860 GII SD, Casio Classpad 330, Casio fx-CG 20, Casio Classpad fx-cp400

Re: fx-9860GII - Arduino - Communication

Postby helder7 » Mon May 20, 2013 2:27 pm

I tested here your code with a homemade cable and with the software Eltima RS232 Data Logger and it sends the string correctly (without ÿ).

Possibly you have to adjust port settings in arduino software. I had a similar problem with my cable and I only solved it by adjusting the port settings in pc.
SiO2 + CaCO3 ----------> CaSiO3 + CO2

Junior Member
Posts: 14
Joined: Fri Apr 26, 2013 5:57 pm
Location: BW, Germany
Calculators: Casio fx-9860 GII

Re: fx-9860GII - Arduino - Communication

Postby Pedantis » Mon May 20, 2013 2:49 pm

Ok, looks like the strange symbols are caused by the serial monitor I used before.

Now, my next question is: how can I insert a string by typing it on the calculator?

Senior Member
Posts: 350
Joined: Tue Jan 03, 2012 11:24 pm
Calculators: Casio Afx 1.0, Casio fx-9860 GII SD, Casio Classpad 330, Casio fx-CG 20, Casio Classpad fx-cp400

Re: fx-9860GII - Arduino - Communication

Postby helder7 » Mon May 20, 2013 4:20 pm

You can use InputString syscall. See the exemple below:

Exemple: Show
syscalls.src
Code: Select all
   .SECTION P,CODE,ALIGN=4
   .MACRO SYSCALL FUNO, SYSCALLNAME, TAIL=nop
   .export \SYSCALLNAME'
\SYSCALLNAME'
   mov.l #h'\FUNO, r0
   mov.l #H'80010070, r2
   jmp @r2
   \TAIL'
   .ENDM

   SYSCALL 040C,   _Serial_ReadOneByte
   SYSCALL 040E,   _Serial_BufferedTransmitOneByte
   SYSCALL 0418,   _Serial_Open
   SYSCALL 0419,   _Serial_Close
   SYSCALL 0414,   _Serial_ClearTransmitBuffer
   SYSCALL 0CC5,   _InputString

   .end


code:
Code: Select all
#include "fxlib.h"
#include "string.h"

int Serial_BufferedTransmitOneByte(unsigned char);
int Serial_Open(void*sm);
int Serial_Close(int mode);
int Serial_ReadOneByte(unsigned char*);
int InputString( unsigned char*buffer, unsigned char *heading, int maxlen );
int i;
int j;
unsigned int key;
unsigned char demo;
char test[20];


int AddIn_main(int isAppli, unsigned short OptionNum)
{
    char mode[6];
    mode[0] = 0;
    mode[1] = 5;
    mode[2] = 2;
    mode[3] = 0;
    mode[4] = 0;
    mode[5] = 0;
    Serial_Open(&mode);
   
   InputString(test,(unsigned char*)"Write some text:",20);
   
   if (strlen(test)>0) {
    for(i=0; i<strlen(test); i++)
    {
        Serial_ClearTransmitBuffer();
        demo=test[i];
        Serial_BufferedTransmitOneByte(demo);
       
        Sleep(100);
        Serial_ClearTransmitBuffer();
        Sleep(100);
    }
   
    Bdisp_AllClr_DDVRAM();
    locate(1,4);
    Print((unsigned char*)"Text");
    locate(1,5);
    Print((unsigned char*)"send!");
    while(1){
        GetKey(&key);
    }
   }

    return 1;
}


#pragma section _BR_Size
unsigned long BR_Size;
#pragma section
#pragma section _TOP
int InitializeSystem(int isAppli, unsigned short OptionNum)
{
    return INIT_ADDIN_APPLICATION(isAppli, OptionNum);
}
#pragma section
SiO2 + CaCO3 ----------> CaSiO3 + CO2

Junior Member
Posts: 14
Joined: Fri Apr 26, 2013 5:57 pm
Location: BW, Germany
Calculators: Casio fx-9860 GII

Re: fx-9860GII - Arduino - Communication

Postby Pedantis » Mon May 20, 2013 5:20 pm

Thanks a lot, helder7!
Is it also possible to send small chars or even things like ä, ö, ü?

EDIT: Right now the space char doen't work...

Senior Member
Posts: 350
Joined: Tue Jan 03, 2012 11:24 pm
Calculators: Casio Afx 1.0, Casio fx-9860 GII SD, Casio Classpad 330, Casio fx-CG 20, Casio Classpad fx-cp400

Re: fx-9860GII - Arduino - Communication

Postby helder7 » Mon May 20, 2013 9:47 pm

Try to use the syscall EditExpression instead of InputString (viewtopic.php?f=20&t=1377). I think this supports spaces. I'm not sure about special multibyte characters like ä, ö, ü.
SiO2 + CaCO3 ----------> CaSiO3 + CO2

Next

Return to General

Who is online

Users browsing this forum: No registered users and 2 guests