kopia lustrzana https://github.com/ogre/pizero_tracker
squash mtx2 devel branch
rodzic
31c3c2456e
commit
d21d3238cc
|
@ -34,3 +34,5 @@
|
|||
# vscode
|
||||
.vscode
|
||||
.vscode/*
|
||||
pcb/eagle/.HabTrackerPiZero_Shield.brd.lck
|
||||
pcb/eagle/.HabTrackerPiZero_Shield.sch.lck
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
#!/bin/env python
|
||||
from __future__ import print_function
|
||||
|
||||
'''
|
||||
Calculate frequency shift for MTX2 module.
|
||||
Reference to resistor numbers in Eagle project.
|
||||
'''
|
||||
|
||||
R1 = 4700
|
||||
R2 = 4700
|
||||
R3 = 22000 + 1000 + 470 # R3 + R4 + R5 in Eagle
|
||||
|
||||
Vcc = 3.3 # volts
|
||||
|
||||
R1_R3 = 1.0/(1.0/R1 + 1.0/R3)
|
||||
R2_R3 = 1.0/(1.0/R2 + 1.0/R3)
|
||||
|
||||
V_Low = R2_R3 / (R2_R3+R1) * Vcc
|
||||
V_High = R2 / (R2+R1_R3) * Vcc
|
||||
V_Diff = V_High - V_Low
|
||||
FreqShift = V_Diff * 2000
|
||||
|
||||
print('R1', R1)
|
||||
print('R2', R2)
|
||||
print('R3', R3)
|
||||
print('R1|R3', R1_R3)
|
||||
print('R2|R3', R2_R3)
|
||||
print('Vcc', Vcc)
|
||||
print('V_Low', V_Low)
|
||||
print('V_High', V_High)
|
||||
print('V_Diff', V_Diff)
|
||||
print('FreqShift', FreqShift)
|
|
@ -8,4 +8,4 @@ include_directories( ${CMAKE_SOURCE_DIR} )
|
|||
|
||||
add_executable( mtx2_test ${mtx2_test_src})
|
||||
|
||||
target_link_libraries( mtx2_test "wiringPi" )
|
||||
target_link_libraries( mtx2_test "pigpio" )
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include "wiringPi.h"
|
||||
#include "pigpio.h"
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
|
@ -94,7 +95,7 @@ int mtx2_write(const int serial_file_descriptor, const std::string& msg)
|
|||
}
|
||||
|
||||
|
||||
void mtx2_set_frequency(const std::string i_device, const float freq_Mhz) // 434.250
|
||||
void mtx2_set_frequency(const int mtx2_enable_pin_gpio, const float freq_Mhz) // 434.250
|
||||
{
|
||||
/*
|
||||
Frequency (in MHz) = 6.5 x (integer + (fraction / 2^19))
|
||||
|
@ -107,7 +108,7 @@ void mtx2_set_frequency(const std::string i_device, const float freq_Mhz) // 434
|
|||
|
||||
using namespace std;
|
||||
|
||||
const float _mtx2comp = (freq_Mhz /* + 0.0015f*/) / 6.5f;
|
||||
const float _mtx2comp = (freq_Mhz + 0.0015f) / 6.5f;
|
||||
const unsigned int _mtx2int = floor(_mtx2comp) - 1;
|
||||
const long _mtx2fractional = (_mtx2comp-_mtx2int) * 524288;
|
||||
|
||||
|
@ -118,16 +119,19 @@ void mtx2_set_frequency(const std::string i_device, const float freq_Mhz) // 434
|
|||
|
||||
char _mtx2command[17];
|
||||
snprintf( _mtx2command, 17, "@PRG_%02X%06lX\r", _mtx2int, _mtx2fractional );
|
||||
// for(size_t i=0; i<sizeof(_mtx2command); ++i) _mtx2command[i] = ~ _mtx2command[i];
|
||||
// printf("MTX2 command is %s\n", _mtx2command);
|
||||
|
||||
for(size_t i=0; i<sizeof(_mtx2command); ++i) _mtx2command[i] = ~ _mtx2command[i];
|
||||
gpioWaveAddNew();
|
||||
gpioWaveAddSerial(mtx2_enable_pin_gpio, 9600, 8, 2, 0, sizeof(_mtx2command), _mtx2command);
|
||||
const int wave_id = gpioWaveCreate();
|
||||
|
||||
printf("MTX2 command is %s\n", _mtx2command);
|
||||
|
||||
/////////
|
||||
//
|
||||
int radio_fd = mtx2_open( i_device, baud_t::k4800 );
|
||||
mtx2_write( radio_fd, _mtx2command, sizeof(_mtx2command) );
|
||||
sleep(1);
|
||||
close(radio_fd);
|
||||
int repetitions = 2;
|
||||
while ( repetitions-- && wave_id >= 0 )
|
||||
{
|
||||
gpioWaveTxSend(wave_id, 0);
|
||||
while (gpioWaveTxBusy())
|
||||
time_sleep(0.1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,4 +23,5 @@ int mtx2_write(const int serial_file_descriptor, const char* msg, const size_t m
|
|||
int mtx2_write(const int serial_file_descriptor, const std::string& msg);
|
||||
|
||||
// will open and close i_device
|
||||
void mtx2_set_frequency(const std::string i_device, const float freq_Mhz); // 434.250
|
||||
// void mtx2_set_frequency(const std::string i_device, const float freq_Mhz); // 434.250
|
||||
void mtx2_set_frequency(const int mtx2_enable_pin, const float freq_Mhz); // 434.250
|
||||
|
|
|
@ -4,18 +4,20 @@
|
|||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include "wiringPi.h"
|
||||
#include "pigpio.h"
|
||||
|
||||
#include "mtx2/mtx2.h"
|
||||
|
||||
const int GPIOPIN_MTX2_EN = 3;
|
||||
// const int GPIOPIN_MTX2_EN_wPI = 3;
|
||||
const unsigned int GPIOPIN_MTX2_EN_gpio = 22;
|
||||
int radio_fd = 0;
|
||||
|
||||
|
||||
void CTRL_C(int sig)
|
||||
{
|
||||
close(radio_fd);
|
||||
digitalWrite (GPIOPIN_MTX2_EN, 0);
|
||||
gpioWrite(GPIOPIN_MTX2_EN_gpio, 0);
|
||||
gpioTerminate();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
@ -23,31 +25,43 @@ void CTRL_C(int sig)
|
|||
int main()
|
||||
{
|
||||
signal(SIGINT, CTRL_C);
|
||||
signal(SIGKILL, CTRL_C);
|
||||
signal(SIGTERM, CTRL_C);
|
||||
|
||||
wiringPiSetup();
|
||||
system("sudo modprobe w1-gpio");
|
||||
|
||||
pinMode (GPIOPIN_MTX2_EN, INPUT);
|
||||
pullUpDnControl(GPIOPIN_MTX2_EN, PUD_DOWN);
|
||||
pinMode (GPIOPIN_MTX2_EN, OUTPUT);
|
||||
if (gpioInitialise() < 0)
|
||||
{
|
||||
std::cerr<<"pigpio initialisation failed\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
gpioSetPullUpDown(GPIOPIN_MTX2_EN_gpio, PI_PUD_DOWN);
|
||||
gpioSetMode(GPIOPIN_MTX2_EN_gpio, PI_OUTPUT);
|
||||
gpioWrite (GPIOPIN_MTX2_EN_gpio, 1);
|
||||
|
||||
mtx2_set_frequency(GPIOPIN_MTX2_EN_gpio, 434.50f);
|
||||
|
||||
const std::string radio_serial_device("/dev/serial0");
|
||||
mtx2_set_frequency(radio_serial_device, 434.580f);
|
||||
mtx2_set_frequency(radio_serial_device, 434.580f);
|
||||
|
||||
radio_fd = mtx2_open(radio_serial_device, baud_t::k50); //"/dev/serial0"
|
||||
digitalWrite (GPIOPIN_MTX2_EN, 1);
|
||||
|
||||
int count = 10;
|
||||
|
||||
int count = 30;
|
||||
while(count--)
|
||||
{
|
||||
std::string msg("message on radio waves !");
|
||||
std::cout<<msg<<" "<<count<<std::endl;
|
||||
|
||||
gpioWrite (GPIOPIN_MTX2_EN_gpio, 1);
|
||||
std::cout<<"bytes: "<<mtx2_write(radio_fd, msg)<<std::endl;
|
||||
gpioWrite (GPIOPIN_MTX2_EN_gpio, 0);
|
||||
std::cout<<"-----"<<std::endl;
|
||||
|
||||
sleep(2);
|
||||
}
|
||||
|
||||
close(radio_fd);
|
||||
digitalWrite (GPIOPIN_MTX2_EN, 0);
|
||||
gpioWrite (GPIOPIN_MTX2_EN_gpio, 0);
|
||||
gpioTerminate();
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue