So i decided to use a hidden variable in Pinguino, _millis. This variable is used in the arduinodelay library and is incremented every milli second. I copied this example of my code:
#include <string.h>
unsigned char caractere;
unsigned char chaine[50];
long tempo;
unsigned char index;
unsigned char gsm_echo(unsigned char state)
{
Serial.flush();
_millis=0;
index=0;
if (state) Serial.print("ATE1\r");
else Serial.print("ATE0\r");
while (_millis<100)
{
if Serial.available()
{
caractere=Serial.read();
chaine[index]=caractere;
index++;
}
}
chaine[index]=0;
if (strstr(chaine,"OK")!=0) return 0;
else return 1;
}
void setup()
{
Serial.begin(9600);
pinMode(0,OUTPUT);
digitalWrite(0,LOW);
tempo=millis();
}
void loop()
{
debut:
delay(500);
if (gsm_echo(0)==1) goto debut;
delay(500);
digitalWrite(0,HIGH);
while (1);
}
The millis instruction in the setup function is just used to initialise the library.
_millis variable is already declared in the arduinodelay library.
Hope it will be useful for everybody.
6 comments:
Hi
I try your source but I've got this error "error millis not yet implemented"
Aleale99
Hey!
I have the same problem!
what version of pinguino do you use ?
Sir please help me make this code work on my pinguino (pic18f2550) Thank you so much.
// ************************************************************************
// Arduino E-Gizmo BT Initializer v00.00.02 by glutnix_neo
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see
//
// ************************************************************************
// Bluetooth Address (Little Endian)
byte BT_Addr[6] = {0x12, 0x13, 0x23, 0x17, 0x08, 0x00}; // any 6 bytes hex digits
byte BT_Alias[15] = {'H', 'E', 'L', 'L', 'O', 0x20, 'W', 'O', 'R', 'L', 'D', 0x20, 0x20, 0x20, 0x20}; // max of 15 characters fill the rest with spaces (0x20)
byte BT_SecurityCode[4] = {'1', '2', '3', '4' }; // 4 digit code
byte BT_InitBuff_Cmd[13] = {0x02, 0x52, 0x27, 0x06, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}; // 6-11
byte BT_SetAlias_Cmd[24] = {0x02, 0x52, 0x04, 0x11, 0x00, 0x67, 0x10, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x03};
byte BT_SetSecurity_Cmd[12] = {0x02, 0x52, 0x17, 0x05, 0x00, 0x6E, 0x04, 0x31, 0x32, 0x33, 0x34, 0x03};
byte BT_StartCore_Cmd[7] = {0x02, 0x52, 0x66, 0x00, 0x00, 0xB8, 0x03};
// Initializes E-Gizmo Bluetooth module to be ready for data transfer, Default data rate is 9600bps
void establishContact()
{
byte i8TempCntr0, i8TempCntr1;
Serial.begin(9600); // Set UART Baudrate to 9600bps
i8TempCntr1 = 0;
for(i8TempCntr0 = 6; i8TempCntr0 < 12; i8TempCntr0++)
{
BT_InitBuff_Cmd[i8TempCntr0] = BT_Addr[i8TempCntr1];
i8TempCntr1++;
}
// Set Blutetooth Address
Serial.write(BT_InitBuff_Cmd,13);
delay(500);
// Parse Bluetooth Alias
i8TempCntr1 = 0;
for(i8TempCntr0 = 7; i8TempCntr0 < 22; i8TempCntr0++)
{
BT_SetAlias_Cmd[i8TempCntr0] = BT_Alias[i8TempCntr1];
i8TempCntr1++;
}
// Set Bluetooth Alias
Serial.write(BT_SetAlias_Cmd,24);
delay(500);
// Parse Bluetooth Security Code
i8TempCntr1 = 0;
for(i8TempCntr0 = 7; i8TempCntr0 < 11; i8TempCntr0++)
{
BT_SetSecurity_Cmd[i8TempCntr0] = BT_SecurityCode[i8TempCntr1];
i8TempCntr1++;
}
// Set Bluetooth Security Code
Serial.write(BT_SetSecurity_Cmd,12);
delay(500);
// Start Bluetooth Core
Serial.write(BT_StartCore_Cmd,7);
delay(500);
}
void setup()
{
establishContact(); // send commands to establish contact
}
void loop()
{
byte incomingByte = 0;
if(Serial.available()>0){
incomingByte = Serial.read();
Serial.print("I received: ");
Serial.println(incomingByte, HEX);
}
}
Can we use hex file created by pinguino with Proteus. I tried but couldn't succeeded. Is there is any simulator like proteus which is compatible with pinguino.
How you obtained your .hex file? The only way I know is by editing the python code.
Anyway, I think the complete code must contain also the bootloader part so, I think it will work if you copy your entire flash code using pickit2 or compatible programmer.
Post a Comment