I am trying to get a very simple ESP8266 project to work but I keep failing and have no clue why.
These are my components:
Wemos D1 (ESP8266MOD)
WS2812B 5050 LED Stripe (2m with 60 LEDs/m)
5V 10A DC Power Supply
This is how I connected everything (I also tried multiple other pins on the controller)
Then I uploaded this code to the controller:
#include <Arduino.h>
#include <Adafruit_NeoPixel.h>
#define PIN D2
#define NUMPIXELS 20
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 500;
void setup() {
pixels.begin();
}
void loop() {
pixels.clear();
for(int i=0;i<NUMPIXELS;i++){
pixels.setPixelColor(i, pixels.Color(0,150,0));
pixels.show();
delay(delayval);
}
}
Absolutely nothing happens. The LEDs remain dark.
I measured the voltage directly on the strip connectors and it's fine. I've got no oszilloscope, but I get varying voltages on the ESPs data pin, so I suppose that's also working as expected.
I also stumbled upon this article stating that the signal voltage has to be at least 60% of the voltage of the stripe while my controller works with 3.3V (seee Datasheet). So I thought this might be part of the problem and tried it again wiht another power supply providing araound 3.8V at max. 5A with the same result. I am running out of ideas. Maybe you have got some for me.
I have a temperature sensor connected to rasberry pi pico and have a main.py, which records the temperature data into .txt file. When I connect the rasberry pi to PC via USB port, it starts recording and saves the data in one .txt file. However, when I connect it to an external power supply (AC DC adapter with output 5V), the data is saved in multiple .txt files of different sizes (named logfile_0001.txt, logfile_0002.txt, ... as expected).
Main.py starts running whenever the rasberry pi is connected to the external power supply, and I can confirm that by the LED, which I programmed it to blink when it starts collecting data and after writing the first three lines.
The weird thing is, I never observe LED blinking more than the initial blink right when it is connected to the external power, even though it should whenever it writes the three header lines. Each separate txt file does contain those three lines as headers. I am very confused how the file can have the three lines without LED blinking, too.
Here is the code after setting up the i2c using machine module in micropython:
#naming the file
num = 0
for file in os.ilistdir():
file_name = file[0]
if not file[0].startswith('logfile'):
continue
temp = int(file_name[8:13])
if temp > num:
num = temp
num += 1
file_name = f'logfile_{num:05d}.txt'
with open(file_name,'w') as f:
f.write('Humidity and temperature data taken using T9602 Humidity & Temperature Sensor, on Rasberry Pi Pico\n')
f.write(str(time.localtime(start_time)) +'\n')
f.write('unixTime Humidity1(%) Temperature1(C) Humidity2(%) Temperature2(C)\n')
#LED blinks when connected
if True:
led_onboard.value(1)
for i in range(3):
led_onboard.value(0)
utime.sleep(0.3)
led_onboard.value(1)
utime.sleep(0.3)
led_onboard.value(0)
while True:
#turn on LED when recording data
led_onboard.value(1)
#communicate with two i2c devices (sensors)
i2c.writeto(address[0],b'1')
i2c2.writeto(address2[0],b'1')
#calculating temperatures based on the data read
RH1, TH1 = data_calc(i2c.readfrom(address[0],4))
with open(file_name, 'a') as f:
f.write(f'{time.time()} {RH1} {TH1} {RH2} {TH2}\n')
print(f'{time.localtime(time.time())[:-2]} {RH1} {TH1} {RH2} {TH2}')
time.sleep(1)
If someone have any insights, I would greatly appreciate it! Thank you so much.
I have this LCD panel:
LED panel's backlight is driven by the MIC2297 chip which takes two signals:
BRT - PWM signal for setting brightness of the LCD's background LEDs.
BL_EN that - gpio signal that enables or disables the LCD's background LEDs.
MIC2297 is powered from the +12V.
Now I connected this display to the Beaglebone Black's (BBB's) expansion connector and I am already running Linux on the BBB's microcontroller AM335x.
In order to enable the backlight I have to properly define it in the device tree i.e. .dts file. Currently I managed to set this up:
backlightt: backlight {
compatible = "pwm-backlight";
pwms = <&ehrpwm1 0 500000000>;
power-supply <>; // ???
enable-gpios = <&gpio2 3 0>;
brightness-levels = <0 4 8 16 32 64 128 255>;
default-brightness-level = <7>;
};
What I don't understand is the property power-supply. How can I know which regulator to use? My devicce uses external 12V! This is really confusing! Why do we even have to specify the regulator?
I found solution...
PWM backlight requires a property "power-supply" that points to some regulator inside the AM335x. This regulator is used to set the output voltage of the PWM - so we don't need to put any kind of voltage regulator between an AM335x and the backlight IC (which might only support 1.5V PWM input on some mobile devices). This is actually really useful.
I'm attempting to sync recorded audio (from an AVAudioEngine inputNode) to an audio file that was playing during the recording process. The result should be like multitrack recording where each subsequent new track is synced with the previous tracks that were playing at the time of recording.
Because sampleTime differs between the AVAudioEngine's output and input nodes, I use hostTime to determine the offset of the original audio and the input buffers.
On iOS, I would assume that I'd have to use AVAudioSession's various latency properties (inputLatency, outputLatency, ioBufferDuration) to reconcile the tracks as well as the host time offset, but I haven't figured out the magic combination to make them work. The same goes for the various AVAudioEngine and Node properties like latency and presentationLatency.
On macOS, AVAudioSession doesn't exist (outside of Catalyst), meaning I don't have access to those numbers. Meanwhile, the latency/presentationLatency properties on the AVAudioNodes report 0.0 in most circumstances. On macOS, I do have access to AudioObjectGetPropertyData and can ask the system about kAudioDevicePropertyLatency, kAudioDevicePropertyBufferSize,kAudioDevicePropertySafetyOffset, etc, but am again at a bit of a loss as to what the formula is to reconcile all of these.
I have a sample project at https://github.com/jnpdx/AudioEngineLoopbackLatencyTest that runs a simple loopback test (on macOS, iOS, or Mac Catalyst) and shows the result. On my Mac, the offset between tracks is ~720 samples. On others' Macs, I've seen as much as 1500 samples offset.
On my iPhone, I can get it close to sample-perfect by using AVAudioSession's outputLatency + inputLatency. However, the same formula leaves things misaligned on my iPad.
What's the magic formula for syncing the input and output timestamps on each platform? I know it may be different on each, which is fine, and I know I won't get 100% accuracy, but I would like to get as close as possible before going through my own calibration process
Here's a sample of my current code (full sync logic can be found at https://github.com/jnpdx/AudioEngineLoopbackLatencyTest/blob/main/AudioEngineLoopbackLatencyTest/AudioManager.swift):
//Schedule playback of original audio during initial playback
let delay = 0.33 * state.secondsToTicks
let audioTime = AVAudioTime(hostTime: mach_absolute_time() + UInt64(delay))
state.audioBuffersScheduledAtHost = audioTime.hostTime
...
//in the inputNode's inputTap, store the first timestamp
audioEngine.inputNode.installTap(onBus: 0, bufferSize: 1024, format: recordingFormat) { (pcmBuffer, timestamp) in
if self.state.inputNodeTapBeganAtHost == 0 {
self.state.inputNodeTapBeganAtHost = timestamp.hostTime
}
}
...
//after playback, attempt to reconcile/sync the timestamps recorded above
let timestampToSyncTo = state.audioBuffersScheduledAtHost
let inputNodeHostTimeDiff = Int64(state.inputNodeTapBeganAtHost) - Int64(timestampToSyncTo)
let inputNodeDiffInSamples = Double(inputNodeHostTimeDiff) / state.secondsToTicks * inputFileBuffer.format.sampleRate //secondsToTicks is calculated using mach_timebase_info
//play the original metronome audio at sample position 0 and try to sync everything else up to it
let originalAudioTime = AVAudioTime(sampleTime: 0, atRate: renderingEngine.mainMixerNode.outputFormat(forBus: 0).sampleRate)
originalAudioPlayerNode.scheduleBuffer(metronomeFileBuffer, at: originalAudioTime, options: []) {
print("Played original audio")
}
//play the tap of the input node at its determined sync time -- this _does not_ appear to line up in the result file
let inputAudioTime = AVAudioTime(sampleTime: AVAudioFramePosition(inputNodeDiffInSamples), atRate: renderingEngine.mainMixerNode.outputFormat(forBus: 0).sampleRate)
recordedInputNodePlayer.scheduleBuffer(inputFileBuffer, at: inputAudioTime, options: []) {
print("Input buffer played")
}
When running the sample app, here's the result I get:
This answer is applicable to native macOS only
General Latency Determination
Output
In the general case the output latency for a stream on a device is determined by the sum of the following properties:
kAudioDevicePropertySafetyOffset
kAudioStreamPropertyLatency
kAudioDevicePropertyLatency
kAudioDevicePropertyBufferFrameSize
The device safety offset, stream, and device latency values should be retrieved for kAudioObjectPropertyScopeOutput.
On my Mac for the audio device MacBook Pro Speakers at 44.1 kHz this equates to 71 + 424 + 11 + 512 = 1018 frames.
Input
Similarly, the input latency is determined by the sum of the following properties:
kAudioDevicePropertySafetyOffset
kAudioStreamPropertyLatency
kAudioDevicePropertyLatency
kAudioDevicePropertyBufferFrameSize
The device safety offset, stream, and device latency values should be retrieved for kAudioObjectPropertyScopeInput.
On my Mac for the audio device MacBook Pro Microphone at 44.1 kHz this equates to 114 + 2404 + 40 + 512 = 3070 frames.
AVAudioEngine
How the information above relates to AVAudioEngine is not immediately clear. Internally AVAudioEngine creates a private aggregate device and Core Audio essentially handles latency compensation for aggregate devices automatically.
During experimentation for this answer I've found that some (most?) audio devices don't report latency correctly. At least that is how it seems, which makes accurate latency determination nigh impossible.
I was able to get fairly accurate synchronization using my Mac's built-in audio using the following adjustments:
// Some non-zero value to get AVAudioEngine running
let startDelay = 0.1
// The original audio file start time
let originalStartingFrame: AVAudioFramePosition = AVAudioFramePosition(playerNode.outputFormat(forBus: 0).sampleRate * startDelay)
// The output tap's first sample is delivered to the device after the buffer is filled once
// A number of zero samples equal to the buffer size is produced initially
let outputStartingFrame: AVAudioFramePosition = Int64(state.outputBufferSizeFrames)
// The first output sample makes it way back into the input tap after accounting for all the latencies
let inputStartingFrame: AVAudioFramePosition = outputStartingFrame - Int64(state.outputLatency + state.outputStreamLatency + state.outputSafetyOffset + state.inputSafetyOffset + state.inputLatency + state.inputStreamLatency)
On my Mac the values reported by the AVAudioEngine aggregate device were:
// Output:
// kAudioDevicePropertySafetyOffset: 144
// kAudioDevicePropertyLatency: 11
// kAudioStreamPropertyLatency: 424
// kAudioDevicePropertyBufferFrameSize: 512
// Input:
// kAudioDevicePropertySafetyOffset: 154
// kAudioDevicePropertyLatency: 0
// kAudioStreamPropertyLatency: 2404
// kAudioDevicePropertyBufferFrameSize: 512
which equated to the following offsets:
originalStartingFrame = 4410
outputStartingFrame = 512
inputStartingFrame = -2625
I may not be able to answer your question, but I believe there is a property not mentioned in your question that does report additional latency information.
I've only worked at the HAL/AUHAL layers (never AVAudioEngine), but in discussions about computing the overall latencies, some audio device/stream properties come up: kAudioDevicePropertyLatency and kAudioStreamPropertyLatency.
Poking around a bit, I see those properties mentioned in the documentation for AVAudioIONode's presentationLatency property (https://developer.apple.com/documentation/avfoundation/avaudioionode/1385631-presentationlatency). I expect that the hardware latency reported by the driver will be there. (I suspect that the standard latency property reports latency for an input sample to appear in the output of a "normal" node, and IO case is special)
It's not in the context of AVAudioEngine, but here's one message from the CoreAudio mailing list that talks a bit about using the low level properties that may provide some additional background: https://lists.apple.com/archives/coreaudio-api/2017/Jul/msg00035.html
My hardware communicate with PC serial port using Tx, Rx and ground lines for sending and receiving data, I wrote a program which can send some text to PC via serial line, now I wanted to alter it in such a way that I should be able to print that data on dot matrix printer which has a serial port.
I am using an Epson LQ 1150 dot matrix printer which has a db25 serial port. I tried connecting in following manner and sent data over serial line, the printer prints some garbage character and hangs.
Tx = Rx
Rx = Tx
Ground = Ground
I tried searching other posts explaining(db9-M to db25-F) :
Receive Data (RxD) 2 = 2 Transmit Data (TxD)
Transmit Data (TxD) 3 = 3 Receive Data (RxD)
Data Terminal Ready (DTR) 4 = 6 Data Set Ready (DSR)
System Ground (SG) 5 = 7 System Ground (SG)
Data Set Ready (DSR) 6 = 20 Data Terminal Ready (DTR)
Clear To Send (CTS) 8 = 4 Request To Send (RTS)
But I don't have DTR, DSR,and CTS. Is there any way I can make it possible using only 3 lines i.e. Tx, Rr and ground?