Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 5 additions & 2 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
"/home/vscode/.arduino15/packages/rp2040/hardware/rp2040/4.0.2/pico-sdk/src/rp2_common/*/include/",
"/home/vscode/.arduino15/packages/rp2040/hardware/rp2040/4.0.2/pico-sdk/src/rp2040/*/include/",
"/home/vscode/.arduino15/packages/rp2040/hardware/rp2040/4.0.2/variants/challenger_2040_nfc/",
"/home/vscode/Arduino/libraries/*/src/"
"/home/vscode/Arduino/libraries/*/src/",
"/home/vscode/Arduino/libraries/Adafruit_NeoPixel"
],
"defines": [
"PICO_RP2040"
],
"defines": ["PICO_RP2040"],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c17",
"cppStandard": "gnu++17",
Expand Down
5 changes: 5 additions & 0 deletions arduino-meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ libraries:
source: arduino
version: "7.3.0"

- name: Adafruit NeoPixel
source: arduino
version: "1.12.4"


cores:
- id: rp2040:rp2040
repository: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
Expand Down
13 changes: 13 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# Get git tag, and massage into something semver-ish
# v1.0.0 if tag exactly, potentially v1.0.0+{n-commits-since-tag}.{commit-hash}.{dirty}
GIT_DESCRIPTION="$(git describe --tags --always --match 'v*' --dirty)"
GIT_DESCRIPTION="${GIT_DESCRIPTION/-/+}"
GIT_DESCRIPTION="${GIT_DESCRIPTION//-/.}"

#DATETIME=$(date --utc '+%Y-%m-%d %H:%M:%S %Z')
VERSION="${GIT_DESCRIPTION}"

arduino-cli compile --output-dir artifacts/ -b rp2040:rp2040:challenger_2040_nfc src \
--build-property "build.extra_flags=\"-DNFCSCANNER_VERSION=\"${VERSION}\"\""
3 changes: 1 addition & 2 deletions build_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ arduino-cli compile --output-dir artifacts/ -b rp2040:rp2040:challenger_2040_nfc
arduino-cli compile --output-dir artifacts/ -b rp2040:rp2040:challenger_2040_nfc poc/ElectronicCats-DetectTags



arduino-cli compile --output-dir artifacts/ -b rp2040:rp2040:challenger_2040_nfc src
./build.sh
10 changes: 10 additions & 0 deletions hardware/Case/Cost calculations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
backplate: 0.96m / 2.32cm³ / 2.87g
top: 26.77m / 64.39cm³ / (calculated 79.835700886g)
bottom: 19.19m / 46151.52mm³ / 57.23g
antenna shelf: 2.21m / 5325.38mm³ / 6.6g


ca. cost for 1x case: 112kr (prusament single spool 1kg, shipped - litt over halve prisen er porto)
this does not account for the back-plate, for example, needing multiple iterations.

Based on a single spool of filament at 30€, and todays currency conversion (XE), and also including the 34.5€ for cheapest shipping (direct from Prusa).
72 changes: 53 additions & 19 deletions src/src.ino
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#ifndef NFCSCANNER_VERSION
#define NFCSCANNER_VERSION "v0.0.0+unknown.manual"
#endif

#include <SPI.h>
#include <Ethernet.h>
#include <Dhcp.h>
Expand All @@ -11,6 +15,8 @@
#undef ERROR
#include <Wire.h>

#include <Adafruit_NeoPixel.h>


#define PN7150_WIRE (Wire1)
#define PN7150_IRQ (uint8_t)(9)
Expand All @@ -20,9 +26,13 @@
#define MAC_EEPROM_ADDR (uint8_t)(0x50)

Electroniccats_PN7150 nfc(PN7150_IRQ, PN7150_VEN, PN7150_ADDR, &PN7150_WIRE);
String getHexRepresentation(const byte* data, const uint32_t numBytes);
String getHexRepresentation(const byte* data, const uint32_t numBytes, const char* prefix="0x", const char* separator=" ");
void displayCardInfo();

// D13 (GP8) = carrier board
// GP14 = challenger
Adafruit_NeoPixel neopixel(1, 8, NEO_GRB + NEO_KHZ800);


byte mac[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
Expand All @@ -41,14 +51,28 @@ HttpClient http = HttpClient(ethernet, url.host(), url.port());
IPAddress my_ip;

void setup() {
neopixel.begin();
neopixel.setBrightness(50);

neopixel.clear();
neopixel.show();
delay(10);

neopixel.fill(neopixel.Color(100, 0, 0));
neopixel.show();


// start serial port:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("NFCScanner "); // TODO: Print version
Serial.println();

neopixel.fill(neopixel.Color(100, 50, 0));
neopixel.show();

Serial.print("NFCScanner ");
Serial.println(NFCSCANNER_VERSION);

// Read MAC address from EEPROM
Wire.begin();
Expand Down Expand Up @@ -99,6 +123,9 @@ void setup() {
http.setHttpWaitForDataDelay(10);
setTimeout(200);

neopixel.fill(neopixel.Color(100, 100, 0));
neopixel.show();

Serial.println("Detect NFC tags with PN7150");

Serial.println("Initializing...");
Expand All @@ -124,6 +151,9 @@ void setup() {
}
nfc.startDiscovery(); // NCI Discovery mode
Serial.println("Waiting for an Card ...");

neopixel.fill(neopixel.Color(0, 100, 0));
neopixel.show();
}

enum TagValidity {
Expand Down Expand Up @@ -263,7 +293,12 @@ void loop() {
//Serial.flush();


if (nfc.isTagDetected(5000)) {
// TODO: Currently waits out the timeout, fails, resets and *then* detects the tag
if (nfc.isTagDetected(500)) {
neopixel.fill(neopixel.Color(0, 0, 100));
neopixel.show();

tone(D5, 2093, 250);
displayCardInfo();

// It can detect multiple cards at the same time if they use the same protocol
Expand All @@ -275,45 +310,44 @@ void loop() {
Serial.println("Remove the Card");
nfc.waitForTagRemoval();
Serial.println("Card removed!");

neopixel.clear();
neopixel.show();
} else {

neopixel.fill(neopixel.Color(100, 0, 0));
neopixel.show();
}

//Serial.println("Restarting...");
nfc.reset();
//Serial.println("Waiting for a Card...");
//delay(500);

neopixel.fill(neopixel.Color(0, 100, 0));
neopixel.show();
}


String getHexRepresentation(const byte* data, const uint32_t numBytes) {
String getHexRepresentation(const byte* data, const uint32_t numBytes, const char* prefix, const char* separator) {
String hexString;

if (numBytes == 0) {
hexString = "null";
}

for (uint32_t szPos = 0; szPos < numBytes; szPos++) {
hexString += "0x";
hexString += prefix;
if (data[szPos] <= 0xF)
hexString += "0";
hexString += String(data[szPos] & 0xFF, HEX);
if ((numBytes > 1) && (szPos != numBytes - 1)) {
hexString += " ";
hexString += separator;
}
}
return hexString;
}

const char* HEX_CHARSET = "0123456789abcdef";
String toHex(const byte* data, const size_t len) {
char res[(len*2)+1] = "";
for (size_t i=0; i<len; i++) {
res[i*2] = HEX_CHARSET[(data[i] & 0xf0) >> 4];
res[(i*2)+1] = HEX_CHARSET[data[i] & 0x0f];;
}
res[len*2] = 0; // Null terminated
return String(res);
}

void displayCardInfo() { // Funtion in charge to show the card/s in te field
char tmp[16];

Expand Down Expand Up @@ -348,7 +382,7 @@ void displayCardInfo() { // Funtion in charge to show the card/s in te field

Serial.print("\tNFC ID = ");
Serial.println(getHexRepresentation(nfc.remoteDevice.getNFCID(), nfc.remoteDevice.getNFCIDLen()));
nfc_id = toHex(nfc.remoteDevice.getNFCID(), nfc.remoteDevice.getNFCIDLen());
nfc_id = getHexRepresentation(nfc.remoteDevice.getNFCID(), nfc.remoteDevice.getNFCIDLen(), "", "");
Serial.println(nfc_id);

Serial.print("\tSEL RES = ");
Expand Down