Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ADCS SW - Attitude Detrmination Control System/README.txt

This file was deleted.

1 change: 0 additions & 1 deletion CDH SW - Command and Data Handling/README.txt

This file was deleted.

1 change: 0 additions & 1 deletion Comms SW - Communication System/README.txt

This file was deleted.

1 change: 0 additions & 1 deletion EPS SW - Electric Power System/README.txt

This file was deleted.

1 change: 0 additions & 1 deletion IFJR SW - In Flight JTAG Reprogrammer/README.txt

This file was deleted.

1 change: 0 additions & 1 deletion RCS SW - Reaction Control System/README.txt

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# CougSat-2 Software
Software Database for CougSat-2
This is the main folder for satellite code, master is deprecated.
102 changes: 102 additions & 0 deletions RP2040 Testing/I2C_TestProject.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/i2c.h"
#include "hardware/adc.h"

#define I2C_PORT i2c0 // Define which I2C port to use
#define I2C_SDA_PIN 16 // Define SDA pin for I2C
#define I2C_SCL_PIN 17 // Define SCL pin for I2C
#define I2C_BUS_ID 0x68
#define I2C_CLOCK 400000 //I2C clock speed, could be upped if necessary, 400khz

void writeBrightness(int brightness, int ledID){

int range= 6+((ledID-1)*4); // Calculate the register address for the LED based on ledID, each LED takes 4 bytes in the register.
int rangeEnd = range + 4; // End of the register range for the LED
// Print the starting register address for debugging purposes
uint8_t brightnessByte = (uint8_t)brightness;//convert to uint8_t from int
for(range; range < rangeEnd; range++){
// Write the brightness value to each register for the LED
//printf("\n%d", &range);
//printf("%d\n", range);
i2c_write_blocking(I2C_PORT, I2C_BUS_ID, (uint8_t*)&range, 1, true); // Send the register address to write to
i2c_write_blocking(I2C_PORT, I2C_BUS_ID, &brightnessByte, 1, false); // Send the brightness value
}
}
int readLightSensor(int diodeNum){
adc_select_input(diodeNum); // Select the ADC input for the specified diode number (0-3)
return adc_read(); // Read the ADC value from the selected input
}
int main()
{
stdio_init_all();
//init the i2c bus
adc_init();
i2c_init(I2C_PORT, I2C_CLOCK); // Initialize I2C with the specified clock speed
//set up analog pins
adc_gpio_init(26);
adc_gpio_init(27);
adc_gpio_init(28);
//config the i2c and make it pull up
gpio_set_function(I2C_SDA_PIN, GPIO_FUNC_I2C); // Set SDA pin to I2C function
gpio_set_function(I2C_SCL_PIN, GPIO_FUNC_I2C); // Set SCL pin to I2C function
gpio_pull_up(I2C_SDA_PIN); // Enable pull-up resistor on SDA pin
gpio_pull_up(I2C_SCL_PIN); // Enable pull-up resistor on SCL pin

//do config for the led breakout board
//write to the board at a specific register
//then you can write what you actually want changed at that register lmao
uint8_t i2c_Value = 0b10101010;//10 sets each individual led to pwm control, page 33 of tlc59116 datasheet, this is the register value to set all LEDs to PWM control. You can change this value to whatever you want for your application.
//write to leds
i2c_write_blocking(I2C_PORT, I2C_BUS_ID, (uint8_t*)0x14, 1, true);
i2c_write_blocking(I2C_PORT, I2C_BUS_ID, &i2c_Value,1, false);

i2c_write_blocking(I2C_PORT, I2C_BUS_ID, (uint8_t*)0x15, 1, true);
i2c_write_blocking(I2C_PORT, I2C_BUS_ID, &i2c_Value,1, false);

i2c_write_blocking(I2C_PORT, I2C_BUS_ID, (uint8_t*)0x16, 1, true);
i2c_write_blocking(I2C_PORT, I2C_BUS_ID, &i2c_Value,1, false);

i2c_write_blocking(I2C_PORT, I2C_BUS_ID, (uint8_t*)0x17, 1, true);
i2c_write_blocking(I2C_PORT, I2C_BUS_ID, &i2c_Value,1, false);

i2c_Value=0;//sets group pwm control brightness control to true
i2c_write_blocking(I2C_PORT, I2C_BUS_ID, (uint8_t*)0x12, 1, true);
i2c_write_blocking(I2C_PORT, I2C_BUS_ID, &i2c_Value,1, false);


while (true) {
gpio_init(18);
gpio_set_dir(18, GPIO_OUT);
gpio_put(18,1);//writes 13 to high, enables system.

i2c_Value=0b00000001;//turn on the oscillator, set to all call bus
i2c_write_blocking(I2C_PORT, I2C_BUS_ID, (uint8_t*)0x00, 1, true);
i2c_write_blocking(I2C_PORT, I2C_BUS_ID, &i2c_Value, 1, false);

i2c_Value=0b00000000; //setup 2nd mode register
i2c_write_blocking(I2C_PORT, I2C_BUS_ID, (uint8_t*)0x01,1,true);
i2c_write_blocking(I2C_PORT, I2C_BUS_ID, &i2c_Value, 1, false);

writeBrightness(255, 0);//test brightness
printf("\n");
writeBrightness(255, 1);//test brightness for LED 2
printf("\n");
writeBrightness(255, 2);//test brightness for LED 3
printf("\n");
writeBrightness(255,3);
int lightReading0 = readLightSensor(0); // Read from the first light sensor (diode 1)
printf("Light Reading 0:\n");
printf("%i \n",lightReading0);

int lightReading1 = readLightSensor(1); // Read from the first light sensor (diode 1)
printf("Light Reading 1:\n");
printf("%i \n",lightReading1);

int lightReading2 = readLightSensor(2); // Read from the first light sensor (diode 1)
printf("Light Reading 2:\n");
printf("%i \n",lightReading2);

sleep_ms(1000);
}
}
19 changes: 19 additions & 0 deletions RP2040 Testing/temperatureSensor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <stdio.h>
#include "pico/stdlib.h"
#include <math.h>

int main()
{
stdio_init_all();

while (true) {
double a = (2.108508173*pow(10,-3));
double b= (0.7979204727*pow(10,-4));
double c = (6.535076315 * pow(10,-7));
double r = 5312.0;//resistence always add .0
double tempK = 1/(a+(b*log(r)+(c*pow(log(r),3))));
double tempC = tempK-273.15;
printf("%f\n",tempC);
sleep_ms(1000);
}
}