![](/media/cache/profiles/profile_pic_for_github_less_than_1MB.jpg.50x50_q85.jpg)
This is example code that can get you started with building your own IR vision robot that communicates over LoRa
Dependencies: Adafruit-MotorShield Adafruit-PWM-Servo-Driver Adafruit_GFX BufferedSerial MAX17055_EZconfig NEO-6m-GPS SX1276GenericLib USBDeviceHT max32630fthr max77650_charger_sample
Fork of MAX326xxFTHR_LoRa_Example_test by
main.cpp@25:1a031add188a, 2018-07-19 (annotated)
- Committer:
- dev_alexander
- Date:
- Thu Jul 19 21:13:19 2018 +0000
- Revision:
- 25:1a031add188a
- Parent:
- 24:e8d03912f303
- Child:
- 26:69aba05f010f
Got messages of different sizes to send to each other. Changed maximum number of bytes per payload to a max value of 255 for more sensor data to be added. Also began debugging the grid eye sensor data acquisition issue.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Helmut64 | 0:c43b6919ae15 | 1 | /* |
Helmut64 | 17:98f2528e8399 | 2 | * Copyright (c) 2018 HELIOS Software GmbH |
Helmut64 | 0:c43b6919ae15 | 3 | * 30826 Garbsen (Hannover) Germany |
Helmut64 | 0:c43b6919ae15 | 4 | * Licensed under the Apache License, Version 2.0); |
Helmut64 | 0:c43b6919ae15 | 5 | */ |
dev_alexander | 21:1b92cabe8a3b | 6 | |
dev_alexander | 21:1b92cabe8a3b | 7 | /* |
dev_alexander | 21:1b92cabe8a3b | 8 | * For Wiring Instructions, please visit the link below: |
dev_alexander | 21:1b92cabe8a3b | 9 | * https://www.hackster.io/DevinAlex64/getting-started-with-the-max32620fthr-and-lora-f9d8dd\ |
dev_alexander | 21:1b92cabe8a3b | 10 | */ |
dev_alexander | 21:1b92cabe8a3b | 11 | |
Helmut64 | 0:c43b6919ae15 | 12 | #include "main.h" |
dev_alexander | 23:f74a50977593 | 13 | #include "global_buffers.h" |
dev_alexander | 23:f74a50977593 | 14 | #include "GridEye.h" |
Helmut64 | 0:c43b6919ae15 | 15 | |
dev_alexander | 23:f74a50977593 | 16 | |
dev_alexander | 23:f74a50977593 | 17 | /* If the board that is compiled is the master device (BLE enabled MAX32630FTHR), |
dev_alexander | 23:f74a50977593 | 18 | * then it needs this library and needs to be configed in order for the device to |
dev_alexander | 23:f74a50977593 | 19 | * work with a 3.3volt output instead of a 1.8 volt output. |
dev_alexander | 23:f74a50977593 | 20 | * |
dev_alexander | 23:f74a50977593 | 21 | * This is only needed for the MAX32630FTHR. The MAX325620FTHR is exampt from this |
dev_alexander | 23:f74a50977593 | 22 | * additional setup in the main program. |
dev_alexander | 23:f74a50977593 | 23 | */ |
dev_alexander | 19:9f035b9e65ec | 24 | #if defined(TARGET_MAX32630FTHR) // using the RFM95 board |
dev_alexander | 19:9f035b9e65ec | 25 | #include "max32630fthr.h" |
dev_alexander | 19:9f035b9e65ec | 26 | MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); |
dev_alexander | 19:9f035b9e65ec | 27 | #endif |
Helmut64 | 0:c43b6919ae15 | 28 | |
Helmut64 | 17:98f2528e8399 | 29 | DigitalOut myled(LED); |
Helmut64 | 0:c43b6919ae15 | 30 | |
dev_alexander | 25:1a031add188a | 31 | Serial pc(USBTX, USBRX); |
dev_alexander | 25:1a031add188a | 32 | |
Helmut64 | 0:c43b6919ae15 | 33 | |
dev_alexander | 23:f74a50977593 | 34 | #if defined(TARGET_MAX32630FTHR) // Master Device: MAX32630FTHR BLE-to-LoRa Gateway |
dev_alexander | 23:f74a50977593 | 35 | /* No grid eye object needed. The function the master uses to convert the raw |
dev_alexander | 23:f74a50977593 | 36 | * data that is sent over from the slave deevice that contains the data from the |
dev_alexander | 23:f74a50977593 | 37 | * actual grid eye sensor is actually a function that is not part of the grid eye |
dev_alexander | 23:f74a50977593 | 38 | * class. this is due to the fact that the grid eye class requires n i2c bus to |
dev_alexander | 23:f74a50977593 | 39 | * be assigned to a phyiscal sensor. In this case, the library for the Grid Eye |
dev_alexander | 23:f74a50977593 | 40 | * sensor has a support functin that is used to convert data that is aquired from |
dev_alexander | 23:f74a50977593 | 41 | * the grid eye sensor. So it is not supposed to be a class specific function. |
dev_alexander | 23:f74a50977593 | 42 | */ |
dev_alexander | 23:f74a50977593 | 43 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: Robot |
dev_alexander | 23:f74a50977593 | 44 | //Init I2C communications in default I2C bus I2C #1 |
dev_alexander | 23:f74a50977593 | 45 | I2C i2cGridEye(P3_4,P3_5); |
dev_alexander | 23:f74a50977593 | 46 | GridEye gridEye(i2cGridEye); |
dev_alexander | 23:f74a50977593 | 47 | #endif |
dev_alexander | 19:9f035b9e65ec | 48 | |
dev_alexander | 23:f74a50977593 | 49 | int main() |
dev_alexander | 23:f74a50977593 | 50 | { |
Helmut64 | 17:98f2528e8399 | 51 | /* |
Helmut64 | 17:98f2528e8399 | 52 | * inits the Serial or USBSerial when available (230400 baud). |
Helmut64 | 17:98f2528e8399 | 53 | * If the serial uart is not is not connected it swiches to USB Serial |
Helmut64 | 17:98f2528e8399 | 54 | * blinking LED means USBSerial detected, waiting for a connect. |
Helmut64 | 17:98f2528e8399 | 55 | * It waits up to 30 seconds for a USB terminal connections |
Helmut64 | 17:98f2528e8399 | 56 | */ |
Helmut64 | 17:98f2528e8399 | 57 | InitSerial(30*1000, &myled); |
Helmut64 | 17:98f2528e8399 | 58 | dprintf("Welcome to the SX1276GenericLib"); |
Helmut64 | 18:d5527ce82e6b | 59 | |
Helmut64 | 17:98f2528e8399 | 60 | dprintf("Starting a simple LoRa PingPong"); |
dev_alexander | 23:f74a50977593 | 61 | |
dev_alexander | 23:f74a50977593 | 62 | /* Setup begins here: */ |
dev_alexander | 25:1a031add188a | 63 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 25:1a031add188a | 64 | dprintf("MAX32630FTHR: Master"); |
dev_alexander | 25:1a031add188a | 65 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot |
dev_alexander | 25:1a031add188a | 66 | dprintf("MAX32620FTHR: Slave"); |
dev_alexander | 25:1a031add188a | 67 | #endif |
dev_alexander | 23:f74a50977593 | 68 | |
dev_alexander | 23:f74a50977593 | 69 | /*************************************************************************** |
dev_alexander | 23:f74a50977593 | 70 | * Lora Communications |
dev_alexander | 23:f74a50977593 | 71 | **************************************************************************/ |
dev_alexander | 22:abca9d17d13d | 72 | SX1276PingPongSetup(); |
dev_alexander | 23:f74a50977593 | 73 | |
dev_alexander | 23:f74a50977593 | 74 | /*************************************************************************** |
dev_alexander | 23:f74a50977593 | 75 | * Grid Eye Sensor: Non-Buffer Program Variables |
dev_alexander | 23:f74a50977593 | 76 | **************************************************************************/ |
dev_alexander | 23:f74a50977593 | 77 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 23:f74a50977593 | 78 | int frame_idx = 0; |
dev_alexander | 24:e8d03912f303 | 79 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot |
dev_alexander | 23:f74a50977593 | 80 | // none yet |
dev_alexander | 25:1a031add188a | 81 | int frame_idx = 0; |
dev_alexander | 23:f74a50977593 | 82 | #endif |
dev_alexander | 23:f74a50977593 | 83 | |
dev_alexander | 23:f74a50977593 | 84 | |
dev_alexander | 22:abca9d17d13d | 85 | while(1) |
dev_alexander | 23:f74a50977593 | 86 | { |
dev_alexander | 23:f74a50977593 | 87 | /*************************************************************************** |
dev_alexander | 23:f74a50977593 | 88 | * Grid Eye Sensor |
dev_alexander | 23:f74a50977593 | 89 | **************************************************************************/ |
dev_alexander | 23:f74a50977593 | 90 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 23:f74a50977593 | 91 | // Check to see if the contents of the previous scan are the same. If they are different then continue with converting |
dev_alexander | 23:f74a50977593 | 92 | if( memcmp(prev_raw_frame_data_from_slave, curr_raw_frame_data_from_slave, sizeof(curr_raw_frame_data_from_slave)) != 0 ) |
dev_alexander | 23:f74a50977593 | 93 | { |
dev_alexander | 23:f74a50977593 | 94 | // Convert raw data sent from slave to a 16 bit integer array by calling this |
dev_alexander | 23:f74a50977593 | 95 | convRaw8x8Data2Point25degC(curr_raw_frame_data_from_slave, conv_frame_data_from_slave); |
dev_alexander | 23:f74a50977593 | 96 | |
dev_alexander | 23:f74a50977593 | 97 | // Next Print off the Converted data |
dev_alexander | 23:f74a50977593 | 98 | dprintf("\r\nFrame %d data: \r\n", frame_idx); |
dev_alexander | 23:f74a50977593 | 99 | uint8_t idx; |
dev_alexander | 23:f74a50977593 | 100 | float pixel_data; |
dev_alexander | 23:f74a50977593 | 101 | for (int y = 0; y < 8; y++) { |
dev_alexander | 23:f74a50977593 | 102 | for (int x = 0; x < 8; x++) { |
dev_alexander | 23:f74a50977593 | 103 | idx = y*8 + x; |
dev_alexander | 23:f74a50977593 | 104 | pixel_data = conv_frame_data_from_slave[idx]/4.0; |
dev_alexander | 23:f74a50977593 | 105 | dprintf("%.2f \t", pixel_data); |
dev_alexander | 23:f74a50977593 | 106 | } |
dev_alexander | 23:f74a50977593 | 107 | dprintf("\r\n\r\n"); |
dev_alexander | 23:f74a50977593 | 108 | } |
dev_alexander | 23:f74a50977593 | 109 | dprintf("\r\n"); |
dev_alexander | 23:f74a50977593 | 110 | |
dev_alexander | 23:f74a50977593 | 111 | // Increment frame counter |
dev_alexander | 23:f74a50977593 | 112 | frame_idx = frame_idx +1; |
dev_alexander | 23:f74a50977593 | 113 | } |
dev_alexander | 25:1a031add188a | 114 | |
dev_alexander | 25:1a031add188a | 115 | /* Next copy in data received from current data into buffer used for |
dev_alexander | 25:1a031add188a | 116 | * comparison next time the memcmp above is called. This prevents the |
dev_alexander | 25:1a031add188a | 117 | * program from converting the same raw data aquired by the grid eye |
dev_alexander | 25:1a031add188a | 118 | * sensor on the slave device to the floating point array with the |
dev_alexander | 25:1a031add188a | 119 | * 0.25 degrees celsius precision level when there is not new data. |
dev_alexander | 25:1a031add188a | 120 | */ |
dev_alexander | 25:1a031add188a | 121 | memcpy(prev_raw_frame_data_from_slave, curr_raw_frame_data_from_slave, sizeof(curr_raw_frame_data_from_slave)); |
dev_alexander | 25:1a031add188a | 122 | |
dev_alexander | 24:e8d03912f303 | 123 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot |
dev_alexander | 23:f74a50977593 | 124 | // Aquire raw data about 8x8 frame from the grid eye sensor in this function call |
dev_alexander | 23:f74a50977593 | 125 | gridEye.getRaw8x8FrameData(curr_raw_frame_data_to_master); |
dev_alexander | 25:1a031add188a | 126 | wait_ms( 1000 ); |
dev_alexander | 25:1a031add188a | 127 | |
dev_alexander | 25:1a031add188a | 128 | //if ( memcmp(prev_raw_frame_data_to_master, curr_raw_frame_data_to_master, sizeof(curr_raw_frame_data_to_master)) != 0 ) |
dev_alexander | 25:1a031add188a | 129 | //{ |
dev_alexander | 25:1a031add188a | 130 | // Convert raw data sent from slave to a 16 bit integer array by calling this |
dev_alexander | 25:1a031add188a | 131 | convRaw8x8Data2Point25degC(curr_raw_frame_data_to_master, conv_frame_data_to_master); |
dev_alexander | 25:1a031add188a | 132 | |
dev_alexander | 25:1a031add188a | 133 | // Next Print off the Converted data |
dev_alexander | 25:1a031add188a | 134 | pc.printf("\r\nFrame %d data: \r\n", frame_idx); |
dev_alexander | 25:1a031add188a | 135 | uint8_t idx; |
dev_alexander | 25:1a031add188a | 136 | float pixel_data; |
dev_alexander | 25:1a031add188a | 137 | for (int y = 0; y < 8; y++) { |
dev_alexander | 25:1a031add188a | 138 | for (int x = 0; x < 8; x++) { |
dev_alexander | 25:1a031add188a | 139 | idx = y*8 + x; |
dev_alexander | 25:1a031add188a | 140 | pixel_data = conv_frame_data_to_master[idx]/4.0; |
dev_alexander | 25:1a031add188a | 141 | pc.printf("%.2f \t", pixel_data); |
dev_alexander | 25:1a031add188a | 142 | } |
dev_alexander | 25:1a031add188a | 143 | pc.printf("\r\n\r\n"); |
dev_alexander | 25:1a031add188a | 144 | } |
dev_alexander | 25:1a031add188a | 145 | pc.printf("\r\n"); |
dev_alexander | 25:1a031add188a | 146 | |
dev_alexander | 25:1a031add188a | 147 | // Increment frame counter |
dev_alexander | 25:1a031add188a | 148 | frame_idx = frame_idx +1; |
dev_alexander | 25:1a031add188a | 149 | //} |
dev_alexander | 25:1a031add188a | 150 | memcpy(prev_raw_frame_data_to_master, curr_raw_frame_data_to_master, sizeof(curr_raw_frame_data_to_master)); |
dev_alexander | 23:f74a50977593 | 151 | #endif |
dev_alexander | 23:f74a50977593 | 152 | |
dev_alexander | 23:f74a50977593 | 153 | /*************************************************************************** |
dev_alexander | 23:f74a50977593 | 154 | * Lora Communications |
dev_alexander | 23:f74a50977593 | 155 | **************************************************************************/ |
dev_alexander | 25:1a031add188a | 156 | wait_ms( 10 ); |
dev_alexander | 22:abca9d17d13d | 157 | SX1276PingPong(); |
dev_alexander | 23:f74a50977593 | 158 | |
dev_alexander | 23:f74a50977593 | 159 | |
dev_alexander | 23:f74a50977593 | 160 | |
dev_alexander | 23:f74a50977593 | 161 | |
dev_alexander | 23:f74a50977593 | 162 | |
dev_alexander | 22:abca9d17d13d | 163 | } |
dev_alexander | 22:abca9d17d13d | 164 | |
Helmut64 | 0:c43b6919ae15 | 165 | } |