We are adding a simpler approach to the simpletools library as well. I'll have a series of short tutorials available for it sometime next week, and will post here when it is ready.
do you have any example of a program that use the i2c library?
I have written this code and gime a lot of errors the SimpleIde. I don't know is because the simplei2c.h ...
thank u!
int pin = 16;
int stacksize = sizeof(_thread_state_t)+sizeof(int)*25;
int *stack = (int*) malloc(stacksize);
int cog;
// initialize wait time to 50ms
wait_time = CLKFREQ/20;
// start the cog
cog = cogstart(funcion_expansores, (void*) pin, stack, stacksize);
funcion_expansores();
return 0;
}
//Se asigna un cog a esta funcion
void funcion_expansores (void) {
/*Se declara un array de enteros donde se almacenaran los bytes de cada expansor*/
unsigned int byte_expansor[numero_servos];
/*Se declara un array de enteros que se usa para indicar si ha habido cambios en los byte de los expansores*/
unsigned int cambio_byte[numero_servos];
/*Se declara un array de enteros donde guardar si ha habido una "interrupcion" en el expansor y hay que leer
de este. IMPORTANTE: esta se
We are adding a simpler approach to the simpletools library as well. I'll have a series of short tutorials available for it sometime next week, and will post here when it is ready.
then if the SimpleIde no work correctly there is no way to check the code?
and are there examples of the use of simplei2c.h?
Thank you all
Check the build status window. It gives all details of building.
All SimpleIDE learn libraries have test code in them. The libsimplei2c has most of it's test code commented out, but you should be able to use the examples there to learn more about the library. I strongly recommend reading the documentation for the library also. Documentation is in your Documents/SimpleIDE/Learn/Simple Libraries Index.html or on line here.
Also, the simpletools library has some eeprom code that uses simplei2c.h.
I have this problem. I want to pass a parameter to a function through the function cogstart, and it's a struct parameter.
Is is could be possible pass a struct parameter?
if so, how can I do it?
Here is an example that uses two instances of a structure to configure two cogs to execute the same code in different ways (different light blinking rates in this case). This uses LEDs connected to the Activity Board's P26 and P27 Propeller I/O pins.
/*
cogrun + struct example
*/
#include "simpletools.h" // Include simpletools library
void blinker(void *par); // Forward declare blinker function
typedef struct blink_st { // blink_st structure
int pinLed;
int timeLed;
} blink_t; // ...assigned blink_t data type
int cog26, cog27; // Cog variables
int stack26[43 + 20]; // Cog stack arrays
int stack27[43 + 20];
int main() // Main function
{
blink_t p26 = {26, 100}; // Create two structure instances
blink_t p27 = {27, 123};
// Launch different cogs with behaviors defined by different data
// structures
cog26 = cogstart(&blinker, &p26, stack26, sizeof stack26);
cog27 = cogstart(&blinker, &p27, stack27, sizeof stack27);
pause(3000); // Watch for 3 s
while(input(27) == 1); // Finish high signal
p27.timeLed = p27.timeLed / 2; // Double one rate
pause(3000); // for 3 more s
cogstop(cog27); // Stop cogs
cogstop(cog26);
}
void blinker(void *par) // Function runs in other cog
{ // Receives struct address through par
blink_t *bp = (blink_t *) par; // Cast address as pointer to blink_t structure
while(1) // Cog's main loop
{
high(bp->pinLed); // LED on using stuct pointer
pause(bp->timeLed); // Delay with struct pointer
low(bp->pinLed); // Etc...
pause(bp->timeLed);
}
}
Thank you!
I have solved one error, but I can't with this. I copy only the important part of code
struct parametros_posicionamiento { /*se definen los parametros que seran necesarios para el posicionamiento
de los servos en una estructura*/
int numero_eje;
int puesta_cero_t_on;
int puesta_cero_t_off;
};
.
.
.
int main(void)
{
struct parametros_posicionamiento pos_eje_1; //Variables estructura que contienen los parametros necesarios
struct parametros_posicionamiento pos_eje_2; //para realizar la puesta a cero de los ejes
struct parametros_posicionamiento pos_eje_3;
.
.
.
case 3: /*estado 3: se ha confirmado encendido de servos y se van a posicionar en referencia*/
parametros_posicionamiento *eje = (parametros_posicionamiento *) par ;
int aux=0;
while (aux != 7 ) { // 7 = 00000111
pulse_out(eje.numero_eje, eje.puesta_cero_t_on);
pause(eje.puesta_cero_t_off);
aux = byte_expansor[eje.numero_eje-1] && 7; //porque empieza en 0
//compruebe tiempo y genere alarma
}
pos_ok++;
}
It's a lot simpler if you type-define your structure. Also, using structType.structElement will not work with the pointer in the function that runs in another cog. You have to use structType->structElement.
Here is your code, adjusted to compile:
#include "simpletools.h"
int stack2[43 + 40];
int stack3[43 + 40];
int stack4[43 + 40];
typedef struct parametros_posicionamiento { /*se definen los parametros que seran necesarios para el posicionamiento
de los servos en una estructura*/
int numero_eje;
int puesta_cero_t_on;
int puesta_cero_t_off;
} par_pos;
void funcion_posicionamiento(void *par);
int main(void)
{
par_pos pos_eje_1; //Variables estructura que contienen los parametros necesarios
par_pos pos_eje_2; //para realizar la puesta a cero de los ejes
par_pos pos_eje_3;
cogstart(&funcion_posicionamiento, &pos_eje_1, stack2, sizeof stack2);
cogstart(&funcion_posicionamiento, &pos_eje_2, stack3, sizeof stack3);
cogstart(&funcion_posicionamiento, &pos_eje_3, stack4, sizeof stack4);
}
void funcion_posicionamiento(void *par)
{
par_pos *eje = (par_pos *) par ;
int aux=0;
while (aux != 7 )
{ // 7 = 00000111
pulse_out(eje->numero_eje, eje->puesta_cero_t_on);
pause(eje->puesta_cero_t_off);
//aux = byte_expansor[eje->numero_eje-1] && 7; //porque empieza en 0
//compruebe tiempo y genere alarma
}
//pos_ok++;
}
P.S. I cannot vouch for runtime errors, but it appears to be free of compiler errors.
Thank you Andy. I have tried that you said but doesn't work.
I don't know if you understood that I want.
I have write a code more clear and clean with the same idea.
This code does work in other compiler but doesn't work with the SimpleIde Compiler
I have tried with "*" too
Yes that's exactly right, I was working and I could solve it, but thank you!
I have a different error, that appear me in this type functions declarations instructions:
I don't know if it's because the "&" or what else...
Note: the "&" operator is only valid in C++. Either rename your source file from something.c to something.cpp, or use the "*" operator instead of the "&" operator to make the error go away.
Note: the "&" operator is only valid in C++. Either rename your source file from something.c to something.cpp, or use the "*" operator instead of the "&" operator to make the error go away.
===Jac
To clarify ....
The & operator in a function signature variable declaration is not valid in C. The pointer * operator should be used instead.
somefunction(int *var); // valid in C/C++ ... specifies the type is a pointer (address of a variable passed to function).
somefunction(int &var); // valid only in C++ ... specifies the type is a reference (alias of a variable passed to function).
When calling somefunction(int *var) ... the & can used by the caller to say use address of variable (pointer to variable).
For C:
void somefunction(int *var)
{
}
int myvar = 0;
somefunction(&myvar);
For C++:
void somefunction(int *var)
{
}
void somefunction(int &var)
{
}
int myvar = 0;
somefunction(&myvar);
somefunction(myvar);
Here is one way to modify your code to make it work. In this case, instead of making the function update a memory address with a result, it returns the result value.
#include "simpletools.h" // Include simple tools
float delta_calcAngleYZ(float x0, float y0, float z0)
{
float theta = x0+y0+z0;
return theta;
}
int main() // Main function
{
float resultado;
resultado = delta_calcAngleYZ(4.0,1.0,2.0);
print(" %f",resultado);
return 0;
}
Comments
Have you looked at the LMM C toggle example?
PropGCC cogstart: https://sites.google.com/site/propellergcc/documentation/libraries/propeller-h-library#TOC-cogstart
Tutorial: http://learn.parallax.com/propeller-c-functions/multicore-example
We are adding a simpler approach to the simpletools library as well. I'll have a series of short tutorials available for it sometime next week, and will post here when it is ready.
I have written this code and gime a lot of errors the SimpleIde. I don't know is because the simplei2c.h ...
thank u!
#include "simpletools.h"
#include "simplei2c.h"
#define numero_servos 3
i2c *i2c_pointer;
void funcion_expansores (void);
int main(void)
{
i2c *i2c_storage;
i2c_pointer = i2c_open(i2c_storage, 37, 38, 0);
int pin = 16;
int stacksize = sizeof(_thread_state_t)+sizeof(int)*25;
int *stack = (int*) malloc(stacksize);
int cog;
// initialize wait time to 50ms
wait_time = CLKFREQ/20;
// start the cog
cog = cogstart(funcion_expansores, (void*) pin, stack, stacksize);
funcion_expansores();
return 0;
}
//Se asigna un cog a esta funcion
void funcion_expansores (void) {
/*Se declara un array de enteros donde se almacenaran los bytes de cada expansor*/
unsigned int byte_expansor[numero_servos];
/*Se declara un array de enteros que se usa para indicar si ha habido cambios en los byte de los expansores*/
unsigned int cambio_byte[numero_servos];
/*Se declara un array de enteros donde guardar si ha habido una "interrupcion" en el expansor y hay que leer
de este. IMPORTANTE: esta se
We posted the Multicore Approaches tutorial here: http://learn.parallax.com/multicore-approaches
This tutorial uses newly-released libraries, so you must update your Learn folder: http://learn.parallax.com/propeller-c-set-simpleide/update-your-learn-folder
why the compiler continue give me errors even in parts of code that are commented: /*....*/ ??
In SimpleIDE?
It is an unintended consequence sometimes of not knowing where the error is (like a linker error). This annoys me too and should be fixed.
BTW, just for context the IDE is not the compiler. It simply tries to interpret the compiler and other program results.
Sorry for the trouble.
and are there examples of the use of simplei2c.h?
Thank you all
Check the build status window. It gives all details of building.
All SimpleIDE learn libraries have test code in them. The libsimplei2c has most of it's test code commented out, but you should be able to use the examples there to learn more about the library. I strongly recommend reading the documentation for the library also. Documentation is in your Documents/SimpleIDE/Learn/Simple Libraries Index.html or on line here.
Also, the simpletools library has some eeprom code that uses simplei2c.h.
I have this problem. I want to pass a parameter to a function through the function cogstart, and it's a struct parameter.
Is is could be possible pass a struct parameter?
if so, how can I do it?
Thank you!
I have solved one error, but I can't with this. I copy only the important part of code the error is exactly this:
Here is your code, adjusted to compile:
P.S. I cannot vouch for runtime errors, but it appears to be free of compiler errors.
I have a different error, that appear me in this type functions declarations instructions:
I don't know if it's because the "&" or what else...?
the part of code of this is the following:
Thank you Andy
I don't know if you understood that I want.
I have write a code more clear and clean with the same idea.
This code does work in other compiler but doesn't work with the SimpleIde Compiler
I have tried with "*" too
Note: the "&" operator is only valid in C++. Either rename your source file from something.c to something.cpp, or use the "*" operator instead of the "&" operator to make the error go away.
===Jac
To clarify ....
The & operator in a function signature variable declaration is not valid in C. The pointer * operator should be used instead.
somefunction(int *var); // valid in C/C++ ... specifies the type is a pointer (address of a variable passed to function).
somefunction(int &var); // valid only in C++ ... specifies the type is a reference (alias of a variable passed to function).
When calling somefunction(int *var) ... the & can used by the caller to say use address of variable (pointer to variable).
For C:
void somefunction(int *var)
{
}
int myvar = 0;
somefunction(&myvar);
For C++:
void somefunction(int *var)
{
}
void somefunction(int &var)
{
}
int myvar = 0;
somefunction(&myvar);
somefunction(myvar);
P.S. In Propeller C, you can reduce the size of a program that displays floating point values by using print instead of printf.