Hello there.
I´m new in this forum, so please be patient with me if i make mistakes or anything.
I do have this project on my education, where i have to send some values from a sensor througha atmega 328P via a nRF24l01+ to a Resparry Pi, I have the transmision up and runing, but now i´m stuck, and i have been for the last 20 days now
I want to send a static value for the sensors ID, and some dynamic value for the mesurement that the sensor has mesuret, at this moment i can only send a static value OR a dynamic value, i hope that some of you would like to give me some ideas hov to combine my static and dynamic data., some of the code i will show belov has danish words in, dont get confused about thet
Code C - [expand] |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
| #define F_CPU 8000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdbool.h>
#include <string.h>
#include <stdio.h>
#include "nrf24l01.h"
#include "nrf24l01-mnemonics.h"
#include "STDIO_UART.h"
void setup_timer(void);
nRF24L01 *setup_rf(void);
volatile bool rf_interrupt = false;
volatile bool send_message = false;
int main(void) {
uint8_t to_address[5] = { 0xc2, 0xc2, 0xc2, 0xc2, 0xc2 };
bool on = false;
sei();
nRF24L01 *rf = setup_rf();
setup_timer();
char text_string[] = "1001:";
void *text_send;
text_send=&text_string;
int tal=1;
int *tal_done;
tal_done=&tal;
while (1) {
if (rf_interrupt)
{
rf_interrupt = false;
int success = nRF24L01_transmit_success(rf);
if (success != 0)
nRF24L01_flush_transmit_message(rf);
}
if (send_message)
{
send_message = false;
on = !on;
nRF24L01Message msg;
memcpy(msg.data, ("%s" ,&text_string ), 10);
msg.length = (strlen((char *)msg.data))+1;
nRF24L01_transmit(rf, to_address, &msg);
(*tal_done)++;
}
}
return 0;
}
nRF24L01 *setup_rf(void) {
nRF24L01 *rf = nRF24L01_init();
rf->ss.port = &PORTB;
rf->ss.pin = PB2;
rf->ce.port = &PORTB;
rf->ce.pin = PB1;
rf->sck.port = &PORTB;
rf->sck.pin = PB5;
rf->mosi.port = &PORTB;
rf->mosi.pin = PB3;
rf->miso.port = &PORTB;
rf->miso.pin = PB4;
// interrupt on falling edge of INT0 (PD2)
EICRA |= _BV(ISC01);
EIMSK |= _BV(INT0);
nRF24L01_begin(rf);
return rf;
}
// setup timer to trigger interrupt every second when at 1MHz
void setup_timer(void) {
TCCR1B |= _BV(WGM12);
TIMSK1 |= _BV(OCIE1A);
//OCR1A = 15624;
OCR1A = 0xFFFF;
TCCR1B |= _BV(CS10) | _BV(CS11);
}
// each one second interrupt
ISR(TIMER1_COMPA_vect) {
send_message = true;
}
// nRF24L01 interrupt
ISR(INT0_vect) {
rf_interrupt = true;
}
*msg are referring to this struct
typedef struct {
int pipe_number;
uint8_t data[32];
uint8_t length;
} nRF24L01Message; |
And it all have to be set in one*msg vareiable for this function
void nRF24L01_transmit(nRF24L01 *rf, void *address, nRF24L01Message *msg);
As the code is now it sends the static ID to the respbarry ( 1001: )
and i just for a start want to have the ( tal ) to be incrementet and sendt with the string for each cycle like
1001:1
1001:2
1001:3
1001:4
1001:5
And so on.
I admit that the startcode is some i had modifyed so far.
I realy hope that some one can see what i want, and how to do it, feel free to ask if there is something i havent covered.
Best regard
Ricky